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.
Implementations on Foreign Types§
source§impl BorshSerialize for SocketAddr
Available on crate feature std
only.
impl BorshSerialize for SocketAddr
Available on crate feature
std
only.source§impl BorshSerialize for StakeState
impl BorshSerialize for StakeState
source§impl BorshSerialize for StakeStateV2
impl BorshSerialize for StakeStateV2
source§impl BorshSerialize for bool
impl BorshSerialize for bool
source§impl BorshSerialize for f32
impl BorshSerialize for f32
source§impl BorshSerialize for f64
impl BorshSerialize for f64
source§impl BorshSerialize for i8
impl BorshSerialize for i8
source§impl BorshSerialize for i16
impl BorshSerialize for i16
source§impl BorshSerialize for i32
impl BorshSerialize for i32
source§impl BorshSerialize for i64
impl BorshSerialize for i64
source§impl BorshSerialize for i128
impl BorshSerialize for i128
source§impl BorshSerialize for isize
impl BorshSerialize for isize
source§impl BorshSerialize for str
impl BorshSerialize for str
source§impl BorshSerialize for u8
impl BorshSerialize for u8
source§impl BorshSerialize for u16
impl BorshSerialize for u16
source§impl BorshSerialize for u32
impl BorshSerialize for u32
source§impl BorshSerialize for u64
impl BorshSerialize for u64
source§impl BorshSerialize for u128
impl BorshSerialize for u128
source§impl BorshSerialize for ()
impl BorshSerialize for ()
source§impl BorshSerialize for usize
impl BorshSerialize for usize
source§impl BorshSerialize for String
impl BorshSerialize for String
source§impl BorshSerialize for Ipv4Addr
Available on crate feature std
only.
impl BorshSerialize for Ipv4Addr
Available on crate feature
std
only.source§impl BorshSerialize for Ipv6Addr
Available on crate feature std
only.
impl BorshSerialize for Ipv6Addr
Available on crate feature
std
only.source§impl BorshSerialize for SocketAddrV4
Available on crate feature std
only.
impl BorshSerialize for SocketAddrV4
Available on crate feature
std
only.source§impl BorshSerialize for SocketAddrV6
Available on crate feature std
only.
impl BorshSerialize for SocketAddrV6
Available on crate feature
std
only.