pub trait BorshSerialize {
    // 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§

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

Provided Methods§

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§

§

impl BorshSerialize for SocketAddr

§

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

§

impl BorshSerialize for bool

§

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

§

impl BorshSerialize for f32

§

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

§

impl BorshSerialize for f64

§

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

§

impl BorshSerialize for i8

§

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

§

impl BorshSerialize for i16

§

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

§

impl BorshSerialize for i32

§

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

§

impl BorshSerialize for i64

§

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

§

impl BorshSerialize for i128

§

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

§

impl BorshSerialize for isize

§

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

§

impl BorshSerialize for str

§

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

§

impl BorshSerialize for u8

§

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

§

impl BorshSerialize for u16

§

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

§

impl BorshSerialize for u32

§

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

§

impl BorshSerialize for u64

§

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

§

impl BorshSerialize for u128

§

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

§

impl BorshSerialize for ()

§

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

§

impl BorshSerialize for usize

§

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

§

impl BorshSerialize for Ipv4Addr

§

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

§

impl BorshSerialize for Ipv6Addr

§

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

§

impl BorshSerialize for SocketAddrV4

§

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

§

impl BorshSerialize for SocketAddrV6

§

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

§

impl BorshSerialize for NonZero<i8>

§

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

§

impl BorshSerialize for NonZero<i16>

§

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

§

impl BorshSerialize for NonZero<i32>

§

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

§

impl BorshSerialize for NonZero<i64>

§

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

§

impl BorshSerialize for NonZero<i128>

§

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

§

impl BorshSerialize for NonZero<u8>

§

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

§

impl BorshSerialize for NonZero<u16>

§

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

§

impl BorshSerialize for NonZero<u32>

§

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

§

impl BorshSerialize for NonZero<u64>

§

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

§

impl BorshSerialize for NonZero<u128>

§

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

§

impl BorshSerialize for NonZero<usize>

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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)

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

Implementors§

source§

impl BorshSerialize for AggregatorResolutionMode

source§

impl BorshSerialize for OracleResponseType

source§

impl BorshSerialize for SwitchboardPermission

§

impl BorshSerialize for StakeState

§

impl BorshSerialize for StakeStateV2

§

impl BorshSerialize for Definition

§

impl BorshSerialize for Fields

source§

impl BorshSerialize for BorshDecimal

source§

impl BorshSerialize for BufferRelayerAccountData

source§

impl BorshSerialize for BufferRelayerRound

source§

impl BorshSerialize for JobAccountData

source§

impl BorshSerialize for AggregatorSaveResultParams

source§

impl BorshSerialize for OracleHeartbeatParams

source§

impl BorshSerialize for PermissionSetParams

§

impl BorshSerialize for StakeFlags

§

impl BorshSerialize for Authorized

§

impl BorshSerialize for Delegation

§

impl BorshSerialize for Lockup

§

impl BorshSerialize for Meta

§

impl BorshSerialize for Stake

§

impl BorshSerialize for Pubkey

§

impl BorshSerialize for String

§

impl BorshSerialize for BorshSchemaContainer

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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