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§

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 BorshSerialize for AssociatedTokenAccountInstruction

§

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

§

impl BorshSerialize for Authorized

§

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

§

impl BorshSerialize for Delegation

§

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

§

impl BorshSerialize for Emit

§

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

§

impl BorshSerialize for Field

§

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

§

impl BorshSerialize for Initialize

§

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

§

impl BorshSerialize for Lockup

§

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

§

impl BorshSerialize for Meta

§

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

§

impl BorshSerialize for OptionalNonZeroPubkey

§

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

§

impl BorshSerialize for PodU32

§

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

§

impl BorshSerialize for PodU64

§

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

§

impl BorshSerialize for RemoveKey

§

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

§

impl BorshSerialize for Stake

§

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

§

impl BorshSerialize for StakeFlags

§

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

§

impl BorshSerialize for StakeState

§

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

§

impl BorshSerialize for StakeStateV2

§

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

§

impl BorshSerialize for TokenMetadata

§

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

§

impl BorshSerialize for UpdateAuthority
where OptionalNonZeroPubkey: BorshSerialize,

§

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

§

impl BorshSerialize for UpdateField

§

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, 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 SwitchboardAttestationPermission

source§

impl BorshSerialize for FunctionStatus

source§

impl BorshSerialize for RequestStatus

source§

impl BorshSerialize for RoutineStatus

source§

impl BorshSerialize for EnclaveRotationStatus

source§

impl BorshSerialize for ServiceStatus

source§

impl BorshSerialize for ServerRegion

source§

impl BorshSerialize for ServerZone

source§

impl BorshSerialize for VerificationStatus

source§

impl BorshSerialize for BoolWithLock

source§

impl BorshSerialize for ResourceLevel

source§

impl BorshSerialize for AggregatorResolutionMode

source§

impl BorshSerialize for OracleResponseType

source§

impl BorshSerialize for SwitchboardPermission

§

impl BorshSerialize for Definition

§

impl BorshSerialize for Fields

source§

impl BorshSerialize for FunctionRequestAccountData

source§

impl BorshSerialize for FunctionRequestTriggerRound

source§

impl BorshSerialize for FunctionRoutineAccountData

source§

impl BorshSerialize for FunctionServiceAccountData

source§

impl BorshSerialize for ServiceRow

source§

impl BorshSerialize for SwitchboardWallet

source§

impl BorshSerialize for FunctionBootedEvent

source§

impl BorshSerialize for FunctionFundEvent

source§

impl BorshSerialize for FunctionInitEvent

source§

impl BorshSerialize for FunctionRequestCloseEvent

source§

impl BorshSerialize for FunctionRequestInitEvent

source§

impl BorshSerialize for FunctionRequestTriggerEvent

source§

impl BorshSerialize for FunctionRequestVerifyErrorEvent

source§

impl BorshSerialize for FunctionRequestVerifyEvent

source§

impl BorshSerialize for FunctionRoutineInitEvent

source§

impl BorshSerialize for FunctionRoutineVerifyErrorEvent

source§

impl BorshSerialize for FunctionRoutineVerifyEvent

source§

impl BorshSerialize for FunctionServiceInitEvent

source§

impl BorshSerialize for FunctionServiceVerifyErrorEvent

source§

impl BorshSerialize for FunctionServiceVerifyEvent

source§

impl BorshSerialize for FunctionSetConfigEvent

source§

impl BorshSerialize for FunctionTriggerEvent

source§

impl BorshSerialize for FunctionVerifyEvent

source§

impl BorshSerialize for FunctionWithdrawEvent

source§

impl BorshSerialize for GarbageCollectionEvent

source§

impl BorshSerialize for PermissionInitEvent

source§

impl BorshSerialize for PermissionSetEvent

source§

impl BorshSerialize for QueueAddMrEnclaveEvent

source§

impl BorshSerialize for QueueInitEvent

source§

impl BorshSerialize for QueueRemoveMrEnclaveEvent

source§

impl BorshSerialize for ServiceRequestQuoteVerifyEvent

source§

impl BorshSerialize for ServiceWorkerAddServiceEvent

source§

impl BorshSerialize for ServiceWorkerAddServiceRequestEvent

source§

impl BorshSerialize for ServiceWorkerInitEvent

source§

impl BorshSerialize for ServiceWorkerRemoveServiceEvent

source§

impl BorshSerialize for ServiceWorkerUpdatedEvent

source§

impl BorshSerialize for VerifierHeartbeatEvent

source§

impl BorshSerialize for VerifierInitEvent

source§

impl BorshSerialize for VerifierQuoteOverrideEvent

source§

impl BorshSerialize for VerifierQuoteRotateEvent

source§

impl BorshSerialize for VerifierQuoteVerifyEvent

source§

impl BorshSerialize for VerifierQuoteVerifyRequestEvent

source§

impl BorshSerialize for AttestationPermissionInitParams

source§

impl BorshSerialize for AttestationPermissionSetParams

source§

impl BorshSerialize for AttestationQueueAddMrEnclaveParams
where [u8; 32]: BorshSerialize,

source§

impl BorshSerialize for AttestationQueueInitParams

source§

impl BorshSerialize for FunctionCloseParams

source§

impl BorshSerialize for FunctionInitParams

source§

impl BorshSerialize for FunctionSetConfigParams

source§

impl BorshSerialize for FunctionSetEscrowParams

source§

impl BorshSerialize for FunctionTriggerParams

source§

impl BorshSerialize for FunctionVerifyParams

source§

impl BorshSerialize for FunctionRequestCloseParams

source§

impl BorshSerialize for FunctionRequestInitParams

source§

impl BorshSerialize for FunctionRequestInitAndTriggerParams

source§

impl BorshSerialize for FunctionRequestSetConfigParams

source§

impl BorshSerialize for FunctionRequestTriggerParams

source§

impl BorshSerialize for FunctionRequestVerifyParams

source§

impl BorshSerialize for FunctionRoutineInitParams

source§

impl BorshSerialize for FunctionRoutineVerifyParams

source§

impl BorshSerialize for ServiceRequestQuoteVerifyParams

source§

impl BorshSerialize for FunctionServiceVerifyParams

source§

impl BorshSerialize for VerifierHeartbeatParams

source§

impl BorshSerialize for VerifierInitParams

source§

impl BorshSerialize for VerifierQuoteRotateParams
where [u8; 64]: BorshSerialize,

source§

impl BorshSerialize for VerifierQuoteVerifyParams

source§

impl BorshSerialize for WalletFundParams

source§

impl BorshSerialize for WalletInitParams

source§

impl BorshSerialize for WalletWithdrawParams

source§

impl BorshSerialize for BootstrapAttestationQueueParams

source§

impl BorshSerialize for BorshQuote

source§

impl BorshSerialize for BorshDecimal

source§

impl BorshSerialize for BufferRelayerAccountData

source§

impl BorshSerialize for BufferRelayerRound

source§

impl BorshSerialize for AccountMetaBorsh

source§

impl BorshSerialize for Callback

source§

impl BorshSerialize for JobAccountData

source§

impl BorshSerialize for AggregatorSaveResultParams

source§

impl BorshSerialize for OracleHeartbeatParams

source§

impl BorshSerialize for PermissionSetParams

source§

impl BorshSerialize for VrfCloseParams

source§

impl BorshSerialize for VrfLiteCloseParams

source§

impl BorshSerialize for VrfLiteRequestRandomnessParams

source§

impl BorshSerialize for VrfPoolRemoveParams

source§

impl BorshSerialize for VrfPoolRequestRandomnessParams

source§

impl BorshSerialize for VrfRequestRandomnessParams

source§

impl BorshSerialize for VrfSetCallbackParams

§

impl BorshSerialize for String

§

impl BorshSerialize for BorshSchemaContainer

§

impl BorshSerialize for Pubkey

§

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, E> BorshSerialize for Result<T, E>

§

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