borsh::ser

Trait BorshSerialize

Source
pub trait BorshSerialize {
    // Required method
    fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>;
}
Expand description

A data-structure that can be serialized into binary format by NBOR.

use borsh::BorshSerialize;

/// derive is only available if borsh is built with `features = ["derive"]`
#[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: Write>(&self, writer: &mut W) -> Result<()>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl BorshSerialize for SocketAddr

Source§

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

Source§

impl BorshSerialize for bool

Source§

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

Source§

impl BorshSerialize for f32

Source§

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

Source§

impl BorshSerialize for f64

Source§

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

Source§

impl BorshSerialize for i8

Source§

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

Source§

impl BorshSerialize for i16

Source§

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

Source§

impl BorshSerialize for i32

Source§

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

Source§

impl BorshSerialize for i64

Source§

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

Source§

impl BorshSerialize for i128

Source§

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

Source§

impl BorshSerialize for isize

Source§

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

Source§

impl BorshSerialize for str

Source§

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

Source§

impl BorshSerialize for u8

Source§

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

Source§

impl BorshSerialize for u16

Source§

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

Source§

impl BorshSerialize for u32

Source§

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

Source§

impl BorshSerialize for u64

Source§

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

Source§

impl BorshSerialize for u128

Source§

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

Source§

impl BorshSerialize for ()

Source§

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

Source§

impl BorshSerialize for usize

Source§

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

Source§

impl BorshSerialize for String

Source§

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

Source§

impl BorshSerialize for Ipv4Addr

Source§

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

Source§

impl BorshSerialize for Ipv6Addr

Source§

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

Source§

impl BorshSerialize for SocketAddrV4

Source§

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

Source§

impl BorshSerialize for SocketAddrV6

Source§

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

Source§

impl BorshSerialize for RangeFull

Source§

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

Source§

impl BorshSerialize for NonZeroI8

Source§

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

Source§

impl BorshSerialize for NonZeroI16

Source§

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

Source§

impl BorshSerialize for NonZeroI32

Source§

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

Source§

impl BorshSerialize for NonZeroI64

Source§

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

Source§

impl BorshSerialize for NonZeroI128

Source§

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

Source§

impl BorshSerialize for NonZeroU8

Source§

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

Source§

impl BorshSerialize for NonZeroU16

Source§

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

Source§

impl BorshSerialize for NonZeroU32

Source§

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

Source§

impl BorshSerialize for NonZeroU64

Source§

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

Source§

impl BorshSerialize for NonZeroU128

Source§

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

Source§

impl BorshSerialize for NonZeroUsize

Source§

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

Source§

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

Source§

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

Source§

impl<K, V, H> BorshSerialize for HashMap<K, V, H>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

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)

Source§

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

Source§

impl<T> BorshSerialize for Cow<'_, T>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> BorshSerialize for Cell<T>
where T: BorshSerialize + Copy,

Source§

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

Source§

impl<T> BorshSerialize for RefCell<T>
where T: BorshSerialize + Sized,

Source§

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

Source§

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

Source§

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

Source§

impl<T, H> BorshSerialize for HashSet<T, H>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T: BorshSerialize> BorshSerialize for RangeFrom<T>

Source§

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

Source§

impl<T: BorshSerialize> BorshSerialize for RangeInclusive<T>

Source§

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

Source§

impl<T: BorshSerialize> BorshSerialize for RangeTo<T>

Source§

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

Source§

impl<T: BorshSerialize> BorshSerialize for RangeToInclusive<T>

Source§

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

Source§

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

Source§

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

Implementors§