I'm trying to use sp_std::collections::btree_map::BTreeMap
for offchain worker Local Storage.
While
let foo = StorageValueRef::persistent(b"bar::foo");
foo.get::<BTreeMap<u32, u32>>();
compiles,
when a custom struct is used as a key as follows:
use sp_core::{Decode, Encode};
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
struct Foo(u32);
let foo = StorageValueRef::persistent(b"bar::foo");
foo.get::<BTreeMap<Foo, u32>>();
compilation fails due to:
18 | foo.get::<BTreeMap<Foo, u32>>();
| ^^^^^^^^^^^^^^^^^^ the trait `sp_core::Decode` is not implemented for `BTreeMap<Foo, u32>`
|
= help: the trait `sp_core::Decode` is implemented for `BTreeMap<K, V>`
Curiously, I can use a sp_std::vec::Vec like so
let foo = StorageValueRef::persistent(b"bar::foo");
foo.get::<Vec<(Foo, u32)>>();
which compiles just fine.