#[repr(transparent)]
pub struct ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,{ /* private fields */ }
Expand description

A list of items that lives inside a managed buffer. Items can be either stored there in full (e.g. u32), or just via handle (e.g. BigUint<M>).

Implementations§

source§

impl<M, T> ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source

pub fn new() -> Self

source§

impl<M, T> ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source

pub fn byte_len(&self) -> usize

Length of the underlying buffer in bytes.

source

pub fn len(&self) -> usize

Number of items.

source

pub fn is_empty(&self) -> bool

source

pub fn try_get(&self, index: usize) -> Option<T::Ref<'_>>

source

pub fn to_array_of_refs<const N: usize>(&self) -> Option<[T::Ref<'_>; N]>

Extracts all elements to an array, if the length matches exactly.

The resulting array contains mere references to the items, as defined in ManagedVecItem.

source

pub fn get(&self, index: usize) -> T::Ref<'_>

Retrieves element at index, if the index is valid. Otherwise, signals an error and terminates execution.

source

pub fn get_mut(&mut self, index: usize) -> ManagedVecRef<'_, M, T>

source

pub fn set(&mut self, index: usize, item: &T) -> Result<(), InvalidSliceError>

source

pub fn slice(&self, start_index: usize, end_index: usize) -> Option<Self>

Returns a new ManagedVec, containing the [start_index, end_index) range of elements. Returns None if any index is out of range

source

pub fn push(&mut self, item: T)

source

pub fn remove(&mut self, index: usize)

source

pub fn from_single_item(item: T) -> Self

New ManagedVec instance with 1 element in it.

source

pub fn overwrite_with_single_item(&mut self, item: T)

source

pub fn append_vec(&mut self, item: ManagedVec<M, T>)

Appends all the contents of another managed vec at the end of the current one. Consumes the other vec in the process.

source

pub fn clear(&mut self)

Removes all items while retaining the handle.

source

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

source

pub fn as_multi(&self) -> &MultiValueManagedVec<M, T>

Creates a reference to and identical object, but one which behaves like a multi-value-vec.

source§

impl<M, T> ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + Ord + Debug,

source

pub fn sort(&mut self)

source

pub fn sort_by<F>(&mut self, compare: F)where F: FnMut(&T, &T) -> Ordering,

source

pub fn sort_by_key<K, F>(&mut self, f: F)where F: FnMut(&T) -> K, K: Ord,

source

pub fn sort_by_cached_key<K, F>(&mut self, f: F)where F: FnMut(&T) -> K, K: Ord,

source

pub fn sort_unstable(&mut self)

source

pub fn sort_unstable_by<F>(&mut self, compare: F)where F: FnMut(&T, &T) -> Ordering,

source

pub fn sort_unstable_by_key<K, F>(&mut self, f: F)where F: FnMut(&T) -> K, K: Ord,

source

pub fn is_sorted(&self) -> bool

source

pub fn is_sorted_by<F>(&self, compare: F) -> boolwhere F: FnMut(&T, &T) -> Option<Ordering>,

source

pub fn is_sorted_by_key<K, F>(&self, f: F) -> boolwhere F: FnMut(&T) -> K, K: Ord,

source§

impl<M, T> ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + PartialEq + Debug,

source

pub fn dedup(&mut self)

source§

impl<M, T> ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + PartialEq,

source

pub fn find(&self, item: &T) -> Option<usize>

This can be very costly for big collections. It needs to deserialize and compare every single item in the worst case.

source

pub fn contains(&self, item: &T) -> bool

This can be very costly for big collections. It needs to iterate, deserialize, and compare every single item in the worst case.

Trait Implementations§

source§

impl<M, T> Clone for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + Clone,

source§

fn clone(&self) -> Self

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<M, T> Debug for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + Debug + Clone,

source§

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

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

impl<M, T> Default for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<M, V> Extend<V> for ManagedVec<M, V>where M: ManagedTypeApi, V: ManagedVecItem,

source§

fn extend<T: IntoIterator<Item = V>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<M, T> From<&ManagedVec<M, T>> for MultiValueEncoded<M, T>where M: ManagedTypeApi, T: ManagedVecItem + TopEncode,

source§

fn from(v: &ManagedVec<M, T>) -> Self

Converts to this type from the input type.
source§

impl<M> From<ManagedVec<M, ManagedBuffer<M>>> for ManagedArgBuffer<M>where M: ManagedTypeApi,

source§

fn from(data: ManagedVec<M, ManagedBuffer<M>>) -> Self

Converts to this type from the input type.
source§

impl<M, T> From<ManagedVec<M, T>> for MultiValueEncoded<M, T>where M: ManagedTypeApi, T: ManagedVecItem + TopEncode + 'static,

source§

fn from(v: ManagedVec<M, T>) -> Self

Converts to this type from the input type.
source§

impl<M, T> From<ManagedVec<M, T>> for MultiValueManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source§

fn from(managed_vec: ManagedVec<M, T>) -> Self

Converts to this type from the input type.
source§

impl<M, T> From<ManagedVec<M, T>> for MultiValueManagedVecCounted<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source§

fn from(v: ManagedVec<M, T>) -> Self

Converts to this type from the input type.
source§

impl<M, T, I> From<Vec<I, Global>> for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem, I: Into<T>,

source§

fn from(v: Vec<I>) -> Self

Converts to this type from the input type.
source§

impl<M, V> FromIterator<V> for ManagedVec<M, V>where M: ManagedTypeApi, V: ManagedVecItem,

source§

fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a, M, T> IntoIterator for &'a ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = ManagedVecOwnedIterator<'a, M, T>

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<M, T> IntoMultiValue for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + IntoMultiValue,

source§

impl<M, T> ManagedType<M> for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

§

type OwnHandle = <M as HandleTypeInfo>::ManagedBufferHandle

source§

fn get_handle(&self) -> M::ManagedBufferHandle

source§

fn transmute_from_handle_ref(handle_ref: &M::ManagedBufferHandle) -> &Self

Implement carefully, since the underlying transmutation is an unsafe operation. For types that wrap a handle to some VM-managed data, make sure the type only contains the handle (plus ZSTs if necessary). For types that just wrap another managed type it is easier, call for the wrapped object.
source§

fn get_raw_handle(&self) -> RawHandle

source§

fn as_ref(&self) -> ManagedRef<'_, M, Self>

source§

impl<M, T> ManagedVecItem for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem,

source§

const PAYLOAD_SIZE: usize = 4usize

Size of the data stored in the underlying ManagedBuffer.
source§

const SKIPS_RESERIALIZATION: bool = false

If true, then the encoding of the item is identical to the payload, and no further conversion is necessary (the underlying buffer can be used as-is during serialization). False for all managed types, but true for basic types (like u32).
§

type Ref<'a> = ManagedRef<'a, M, ManagedVec<M, T>>

Reference representation of the ManagedVec item. Read more
source§

fn from_byte_reader<Reader: FnMut(&mut [u8])>(reader: Reader) -> Self

Parses given bytes as a an owned object.
source§

unsafe fn from_byte_reader_as_borrow<'a, Reader: FnMut(&mut [u8])>( reader: Reader ) -> Self::Ref<'a>

Parses given bytes as a representation of the object, either owned, or a reference. Read more
source§

fn to_byte_writer<R, Writer: FnMut(&[u8]) -> R>(&self, writer: Writer) -> R

source§

impl<M, T> NestedDecode for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + NestedDecode,

source§

fn dep_decode_or_handle_err<I, H>( input: &mut I, h: H ) -> Result<Self, H::HandledErr>where I: NestedDecodeInput, H: DecodeErrorHandler,

Version of dep_decode that can handle errors as soon as they occur. For instance in can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.
source§

fn dep_decode<I>(input: &mut I) -> Result<Self, DecodeError>where I: NestedDecodeInput,

Attempt to deserialise the value from input, using the format of an object nested inside another structure. In case of success returns the deserialized value and the number of bytes consumed during the operation.
source§

impl<M, T> NestedEncode for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + NestedEncode,

source§

fn dep_encode_or_handle_err<O, H>( &self, dest: &mut O, h: H ) -> Result<(), H::HandledErr>where O: NestedEncodeOutput, H: EncodeErrorHandler,

Version of dep_encode that can handle errors as soon as they occur. For instance in can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.
source§

fn dep_encode<O>(&self, dest: &mut O) -> Result<(), EncodeError>where O: NestedEncodeOutput,

NestedEncode to output, using the format of an object nested inside another structure. Does not provide compact version.
source§

impl<M, T> PartialEq<ManagedVec<M, T>> for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<M, T> TopDecode for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + NestedDecode,

source§

fn top_decode_or_handle_err<I, H>(input: I, h: H) -> Result<Self, H::HandledErr>where I: TopDecodeInput, H: DecodeErrorHandler,

Version of top_decode that can handle errors as soon as they occur. For instance it can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.
source§

fn top_decode<I>(input: I) -> Result<Self, DecodeError>where I: TopDecodeInput,

Attempt to deserialize the value from input.
source§

impl<M, T> TopEncode for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + NestedEncode,

source§

fn top_encode_or_handle_err<O, H>( &self, output: O, h: H ) -> Result<(), H::HandledErr>where O: TopEncodeOutput, H: EncodeErrorHandler,

Version of top_encode that can handle errors as soon as they occur. For instance in can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.
source§

fn top_encode<O>(&self, output: O) -> Result<(), EncodeError>where O: TopEncodeOutput,

Attempt to serialize the value to ouput.
source§

impl<M> TopEncodeMultiOutput for ManagedVec<M, ManagedBuffer<M>>where M: ManagedTypeApi,

source§

fn push_single_value<T, H>( &mut self, arg: &T, h: H ) -> Result<(), H::HandledErr>where T: TopEncode, H: EncodeErrorHandler,

source§

fn push_multi_specialized<T, H>( &mut self, _arg: &T, h: H ) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where T: TryStaticCast, H: EncodeErrorHandler,

This is temporary, will remove after we get rid of SCResult for good.
source§

impl<M, T> TypeAbi for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + TypeAbi,

source§

fn type_name() -> TypeName

It is semantically equivalent to any list of T.

source§

fn provide_type_descriptions<TDC: TypeDescriptionContainer>( accumulator: &mut TDC )

A type can provide more than its own description. For instance, a struct can also provide the descriptions of the type of its fields. TypeAbi doesn’t care for the exact accumulator type, which is abstracted by the TypeDescriptionContainer trait.
source§

impl<M, T> Eq for ManagedVec<M, T>where M: ManagedTypeApi, T: ManagedVecItem + PartialEq,

Auto Trait Implementations§

§

impl<M, T> CodecFromSelf for ManagedVec<M, T>where T: CodecFromSelf,

§

impl<M, T> RefUnwindSafe for ManagedVec<M, T>where T: RefUnwindSafe, <M as HandleTypeInfo>::ManagedBufferHandle: RefUnwindSafe,

§

impl<M, T> Send for ManagedVec<M, T>where T: Send, <M as HandleTypeInfo>::ManagedBufferHandle: Send,

§

impl<M, T> Sync for ManagedVec<M, T>where T: Sync, <M as HandleTypeInfo>::ManagedBufferHandle: Sync,

§

impl<M, T> Unpin for ManagedVec<M, T>where T: Unpin, <M as HandleTypeInfo>::ManagedBufferHandle: Unpin,

§

impl<M, T> UnwindSafe for ManagedVec<M, T>where T: UnwindSafe, <M as HandleTypeInfo>::ManagedBufferHandle: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 Twhere 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> SCCodec for Twhere T: TopEncode,

source§

fn fmt<F>(&self, f: &mut F)where F: FormatByteReceiver,

source§

impl<T> ToOwned for Twhere T: Clone,

§

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> TopDecodeMulti for Twhere T: TopDecode,

source§

const IS_SINGLE_VALUE: bool = true

Used to optimize single value loading of endpoint arguments.
source§

fn multi_decode_or_handle_err<I, H>( input: &mut I, h: H ) -> Result<T, <H as DecodeErrorHandler>::HandledErr>where I: TopDecodeMultiInput, H: DecodeErrorHandler,

source§

fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>where I: TopDecodeMultiInput,

source§

impl<T> TopDecodeMultiLength for Twhere T: TopEncode + TopDecode,

source§

const LEN: usize = 1usize

source§

fn get_len() -> usize

source§

impl<T> TopEncodeMulti for Twhere T: TopEncode,

source§

fn multi_encode_or_handle_err<O, H>( &self, output: &mut O, h: H ) -> Result<(), <H as EncodeErrorHandler>::HandledErr>where O: TopEncodeMultiOutput, H: EncodeErrorHandler,

Version of top_encode that can handle errors as soon as they occur. For instance in can exit immediately and make sure that if it returns, it is a success. By not deferring error handling, this can lead to somewhat smaller bytecode.
source§

fn multi_encode<O>(&self, output: &mut O) -> Result<(), EncodeError>where O: TopEncodeMultiOutput,

Attempt to serialize the value to ouput.
source§

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

§

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 Twhere U: TryFrom<T>,

§

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<'a, T> CodecFrom<&'a T> for Twhere &'a T: TopEncodeMulti, T: TopDecodeMulti,

source§

impl<T> CodecFrom<PlaceholderInput> for Twhere T: TopDecodeMulti + CodecFromSelf,

source§

impl<T> CodecFrom<T> for Twhere T: TopEncodeMulti + TopDecodeMulti + CodecFromSelf,

source§

impl<F, I> CodecInto<F> for Iwhere I: TopEncodeMulti, F: CodecFrom<I>,