This crate contains three [derive macros] for [casper_types::CLTyped
],
[casper_types::bytesrepr::FromBytes
] and [casper_types::bytesrepr::ToBytes
].
You might want to implement these three traits for a struct
you want to store in [Casper] storage. See storage API documentation on [docs.casperlabs.io].
A macro declared on a struct like this:
```rust use caspertypesderive::{CLTyped, ToBytes, FromBytes};
struct Dog {
name: String,
likes_treat: BTreeMap
Will expand into this:
```rust impl CLTypes for Dog { fn cl_type(&self) -> CLType { CLType::Any } }
impl FromBytes for Dog { fn frombytes(bytes: &[u8]) -> Result<(Self, &[u8]), caspertypes::bytesrepr::Error> { let (name, bytes) = FromBytes::frombytes(bytes)?; let (likestreat, bytes) = FromBytes::frombytes(bytes)?; let value = Dog { name, likestreat, }; Ok((value, bytes)) } }
impl ToBytes for Dog { fn serializedlength(&self) -> usize { let mut size = 0; size += name.serializedlength(); size += likestreat.serializedlength(); return size; }
fn tobytes(&self) -> Result