pub trait AnchorSerialize {
    fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
    where
        W: Write
; fn try_to_vec(&self) -> Result<Vec<u8, Global>, Error> { ... } }
Expand description

Borsh is the default serialization format for instructions and accounts. 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

Serialize this instance into a vector of bytes.

Implementations on Foreign Types

Implementors