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§

source

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

Provided Methods§

source

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl BorshSerialize for SocketAddr

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for StakeState

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for StakeStateV2

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for bool

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for f32

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for f64

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for i8

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for i16

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for i32

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for i64

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for i128

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for isize

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for str

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for u8

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for u16

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for u32

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for u64

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for u128

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for ()

source§

fn serialize<W>(&self, _writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for usize

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for String

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Ipv4Addr

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Ipv6Addr

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for SocketAddrV4

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for SocketAddrV6

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroI8

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroI16

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroI32

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroI64

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroI128

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroU8

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroU16

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroU32

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroU64

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroU128

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for NonZeroUsize

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Hash

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Hash

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Hash

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Secp256k1Pubkey

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for StakeFlagswhere u8: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Authorizedwhere Pubkey: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Delegationwhere Pubkey: BorshSerialize, u64: BorshSerialize, f64: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Lockupwhere i64: BorshSerialize, u64: BorshSerialize, Pubkey: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Metawhere u64: BorshSerialize, Authorized: BorshSerialize, Lockup: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl BorshSerialize for Stakewhere Delegation: BorshSerialize, u64: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<K, V> BorshSerialize for BTreeMap<K, V>where K: BorshSerialize, V: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<K, V, H> BorshSerialize for HashMap<K, V, H>where K: BorshSerialize + PartialOrd, V: BorshSerialize, H: BuildHasher,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0> BorshSerialize for (T0,)where T0: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1> BorshSerialize for (T0, T1)where T0: BorshSerialize, T1: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2> BorshSerialize for (T0, T1, T2)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3> BorshSerialize for (T0, T1, T2, T3)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4> BorshSerialize for (T0, T1, T2, T3, T4)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5> BorshSerialize for (T0, T1, T2, T3, T4, T5)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize, T15: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize, T15: BorshSerialize, T16: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize, T15: BorshSerialize, T16: BorshSerialize, T17: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize, T15: BorshSerialize, T16: BorshSerialize, T17: BorshSerialize, T18: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19> BorshSerialize for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19)where T0: BorshSerialize, T1: BorshSerialize, T2: BorshSerialize, T3: BorshSerialize, T4: BorshSerialize, T5: BorshSerialize, T6: BorshSerialize, T7: BorshSerialize, T8: BorshSerialize, T9: BorshSerialize, T10: BorshSerialize, T11: BorshSerialize, T12: BorshSerialize, T13: BorshSerialize, T14: BorshSerialize, T15: BorshSerialize, T16: BorshSerialize, T17: BorshSerialize, T18: BorshSerialize, T19: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for Cow<'_, T>where T: BorshSerialize + ToOwned + ?Sized,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for Option<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for &Twhere T: BorshSerialize + ?Sized,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for [T]where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for Box<T>where T: BorshSerialize + ?Sized,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for BinaryHeap<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for BTreeSet<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for LinkedList<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for VecDeque<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for Vec<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for PhantomData<T>where T: ?Sized,

source§

fn serialize<W>(&self, _: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T> BorshSerialize for Range<T>where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T, E> BorshSerialize for Result<T, E>where T: BorshSerialize, E: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T, H> BorshSerialize for HashSet<T, H>where T: BorshSerialize + PartialOrd, H: BuildHasher,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

source§

impl<T, const N: usize> BorshSerialize for [T; N]where T: BorshSerialize,

source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>where W: Write,

Implementors§