Trait anchor_lang::AnchorSerialize
source · pub trait AnchorSerialize {
// Required method
fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write;
// Provided method
fn try_to_vec(&self) -> Result<Vec<u8>, Error> { ... }
}
Expand description
A data-structure that can be serialized into binary format by NBOR.
use borsh::BorshSerialize;
#[derive(BorshSerialize)]
struct MyBorshSerializableStruct {
value: String,
}
let x = MyBorshSerializableStruct { value: "hello".to_owned() };
let mut buffer: Vec<u8> = Vec::new();
x.serialize(&mut buffer).unwrap();
let single_serialized_buffer_len = buffer.len();
x.serialize(&mut buffer).unwrap();
assert_eq!(buffer.len(), single_serialized_buffer_len * 2);
let mut buffer: Vec<u8> = vec![0; 1024 + single_serialized_buffer_len];
let mut buffer_slice_enough_for_the_data = &mut buffer[1024..1024 + single_serialized_buffer_len];
x.serialize(&mut buffer_slice_enough_for_the_data).unwrap();
Required Methods§
Provided Methods§
Object Safety§
This trait is not object safe.