pub trait StorageItem {
    type Key: Eq;
    type Error: StorageItemError;

    fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, Self::Error>;
    fn deserialize_from(buffer: &[u8]) -> Result<(Self, usize), Self::Error>
    where
        Self: Sized
; fn key(&self) -> Self::Key; }
Expand description

A way of serializing and deserializing items in the storage.

A serialized byte pattern of all 0xFF is invalid and must never be the result of the serialize_into function and deserialize_from must always return an error for it.

The given buffer to serialize in and deserialize from is never bigger than MAX_STORAGE_ITEM_SIZE bytes, so make sure the item is smaller than that.

Required Associated Types§

The key type of the key-value pair

The error type for serialization and deserialization

Required Methods§

Serialize the key-value item into the given buffer. Returns the number of bytes the buffer was filled with or an error.

The serialized bytes must not all be 0xFF. One way to prevent this is to serialize an extra 0 byte at the end if that is the case.

Deserialize the key-value item from the given buffer. The buffer is likely bigger than the size of the item.

The key of the key-value item. It is used by the storage to know what the key of this item is.

Implementors§