pub trait Chunkable {
type Error: Debug;
// Required method
fn as_bytes(&self) -> Result<Cow<'_, Vec<u8>>, Self::Error>;
// Provided method
fn hash(&self) -> Result<Digest, Self::Error> { ... }
}Expand description
Implemented for types that are chunked when sending over the wire and/or before storing the trie store.
Required Associated Types§
Required Methods§
Sourcefn as_bytes(&self) -> Result<Cow<'_, Vec<u8>>, Self::Error>
fn as_bytes(&self) -> Result<Cow<'_, Vec<u8>>, Self::Error>
Maps Self into bytes.
Returns a Cow instance in case the resulting bytes are the same as input and we don’t
want to reinitialize. This also helps with a case where returning a vector of bytes
would require instantiating a Vec<u8> locally (see casper_types::bytesrepr::ToBytes)
but can’t be returned as reference. Alternative encoding would be to consume Self and
return Vec<u8> but that may do it unnecessarily if Self would be to used again.