Trait fadroma::storage::Key

source ·
pub trait Key {
    // Required methods
    fn size(&self) -> usize;
    fn write_segments(&self, buf: &mut Vec<u8>);
}
Expand description

Implemented for types that act as CW storage keys by writing bytes into the given buffer. What those bytes represent and where they are coming from as well as how they are written into the buffer entirely depends on the implementing type.

The Key::size method is used to report the amount of bytes that the key will write. This allows us to efficiently allocate the exact amount of memory that we will need to construct the final key. It exists because the provided buffer might be larger than the size of the given key since multiple keys can be concatenated or a prefix (such as a Namespace) might be added to the final key. This depends entirely on the given scenario and is taken care of by the storage types. There are already several key types provided which should cover pretty much all use cases.

Required Methods§

source

fn size(&self) -> usize

source

fn write_segments(&self, buf: &mut Vec<u8>)

Implementors§

source§

impl Key for StaticKey

source§

impl<'a> Key for CompositeKey<'a>

source§

impl<'a, T1: Segment + ?Sized, T2: Segment + ?Sized> Key for TypedKey2<'a, T1, T2>

source§

impl<'a, T1: Segment + ?Sized, T2: Segment + ?Sized, T3: Segment + ?Sized> Key for TypedKey3<'a, T1, T2, T3>

source§

impl<'a, T1: Segment + ?Sized, T2: Segment + ?Sized, T3: Segment + ?Sized, T4: Segment + ?Sized> Key for TypedKey4<'a, T1, T2, T3, T4>

source§

impl<'a, T: Segment + ?Sized> Key for TypedKey<'a, T>

source§

impl<'a, const N: usize> Key for FixedSegmentSizeKey<'a, N>

source§

impl<T: Namespace> Key for T