Struct PrefixedVec

Source
pub struct PrefixedVec<L, T> { /* private fields */ }
Expand description

PrefixedVec allows overriding the default u8 size of the length prefix for a Vec.

This is useful when the size of a Vec is greater than 255 and we wish to override the Pyth serialization logic to use a u16 etc instead. This works by serializing the Vec as a struct with a len field with the overridden type, when combined with PrefixlessVec below the combination of { "len": L, "data": [T] } is serialized as expected in the wire format.

For non-Pyth formats this results in a struct which is the correct way to interpret our data on chain anyway.

Implementations§

Source§

impl<L, T> PrefixedVec<L, T>

Source

pub fn iter(&self) -> Iter<'_, T>

Trait Implementations§

Source§

impl<L, T> AsRef<Vec<T>> for PrefixedVec<L, T>

Source§

fn as_ref(&self) -> &Vec<T>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L, T> BorshDeserialize for PrefixedVec<L, T>
where PhantomData<L>: BorshDeserialize, PrefixlessVec<T>: BorshDeserialize,

Source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl<L, T> BorshSerialize for PrefixedVec<L, T>
where PhantomData<L>: BorshSerialize, PrefixlessVec<T>: BorshSerialize,

Source§

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

Source§

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

Serialize this instance into a vector of bytes.
Source§

impl<L: Clone, T: Clone> Clone for PrefixedVec<L, T>

Source§

fn clone(&self) -> PrefixedVec<L, T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug, T: Debug> Debug for PrefixedVec<L, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, L, T> Deserialize<'de> for PrefixedVec<L, T>
where T: Deserialize<'de>, L: Deserialize<'de> + Into<usize> + Copy,

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<L, T> From<PrefixedVec<L, T>> for Vec<T>

Source§

fn from(data: PrefixedVec<L, T>) -> Self

Converts to this type from the input type.
Source§

impl<L, T> From<Vec<T>> for PrefixedVec<L, T>

Source§

fn from(data: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<L: Hash, T: Hash> Hash for PrefixedVec<L, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<L, T> IntoIterator for PrefixedVec<L, T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<PrefixedVec<L, T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<L: PartialEq, T: PartialEq> PartialEq for PrefixedVec<L, T>

Source§

fn eq(&self, other: &PrefixedVec<L, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L: PartialOrd, T: PartialOrd> PartialOrd for PrefixedVec<L, T>

Source§

fn partial_cmp(&self, other: &PrefixedVec<L, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<L, T> Serialize for PrefixedVec<L, T>
where T: Serialize, L: Serialize + TryFrom<usize>, <L as TryFrom<usize>>::Error: Debug,

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<L, T> StructuralPartialEq for PrefixedVec<L, T>

Auto Trait Implementations§

§

impl<L, T> Freeze for PrefixedVec<L, T>

§

impl<L, T> RefUnwindSafe for PrefixedVec<L, T>

§

impl<L, T> Send for PrefixedVec<L, T>
where L: Send, T: Send,

§

impl<L, T> Sync for PrefixedVec<L, T>
where L: Sync, T: Sync,

§

impl<L, T> Unpin for PrefixedVec<L, T>
where L: Unpin, T: Unpin,

§

impl<L, T> UnwindSafe for PrefixedVec<L, T>
where L: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,