pub struct TypedKey<'a, T: Segment + ?Sized>(_);
Expand description
A strongly-typed key with segments defined by the concrete type
which must implement Segment
. For typed keys which consist of
multiple types use TypedKey2
, TypedKey3
and TypedKey4
.
Constructs the key in order of definition.
Examples
use fadroma::{
cosmwasm_std::testing::mock_dependencies,
storage::{Key, ItemSpace, TypedKey2}
};
fadroma::namespace!(NumbersNs, b"numbers");
// Storage for u64 numbers with a key that consists of b"numbers" + a string + a byte.
const NUMBERS: ItemSpace::<u64, NumbersNs, TypedKey2<String, u8>> = ItemSpace::new();
let mut deps = mock_dependencies();
let storage = deps.as_mut().storage;
let string_segment = "hello".to_string();
let number_segment = 33u8;
NUMBERS.save(storage, (&string_segment, &number_segment), &1).unwrap();
// Can also be constructed like this
let key = TypedKey2::from((&string_segment, &number_segment));
NUMBERS.save(storage, key.clone(), &1).unwrap();
let mut bytes: Vec<u8> = Vec::with_capacity(key.size());
key.write_segments(&mut bytes);
assert_eq!(
bytes,
[string_segment.as_bytes(), &number_segment.to_be_bytes()].concat()
);
Trait Implementations§
source§impl<'a, T: PartialEq + Segment + ?Sized> PartialEq<TypedKey<'a, T>> for TypedKey<'a, T>
impl<'a, T: PartialEq + Segment + ?Sized> PartialEq<TypedKey<'a, T>> for TypedKey<'a, T>
impl<'a, T: Copy + Segment + ?Sized> Copy for TypedKey<'a, T>
impl<'a, T: Segment + ?Sized> StructuralPartialEq for TypedKey<'a, T>
Auto Trait Implementations§
impl<'a, T: ?Sized> RefUnwindSafe for TypedKey<'a, T>where T: RefUnwindSafe,
impl<'a, T: ?Sized> Send for TypedKey<'a, T>where T: Sync,
impl<'a, T: ?Sized> Sync for TypedKey<'a, T>where T: Sync,
impl<'a, T: ?Sized> Unpin for TypedKey<'a, T>
impl<'a, T: ?Sized> UnwindSafe for TypedKey<'a, T>where T: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more