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.