Struct dharitri_wasm::types::ManagedVec
source · 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,
impl<M, T> ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
source§impl<M, T> ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
impl<M, T> ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
pub fn is_empty(&self) -> bool
pub fn try_get(&self, index: usize) -> Option<T::Ref<'_>>
sourcepub fn to_array_of_refs<const N: usize>(&self) -> Option<[T::Ref<'_>; N]>
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.
sourcepub fn get(&self, index: usize) -> T::Ref<'_>
pub fn get(&self, index: usize) -> T::Ref<'_>
Retrieves element at index, if the index is valid. Otherwise, signals an error and terminates execution.
pub fn get_mut(&mut self, index: usize) -> ManagedVecRef<'_, M, T>
pub fn set(&mut self, index: usize, item: &T) -> Result<(), InvalidSliceError>
pub fn slice(&self, start_index: usize, end_index: usize) -> Option<Self>
pub fn push(&mut self, item: T)
pub fn remove(&mut self, index: usize)
sourcepub fn from_single_item(item: T) -> Self
pub fn from_single_item(item: T) -> Self
New ManagedVec instance with 1 element in it.
pub fn overwrite_with_single_item(&mut self, item: T)
sourcepub fn append_vec(&mut self, item: ManagedVec<M, T>)
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.
pub fn iter(&self) -> ManagedVecRefIterator<'_, M, T> ⓘ
sourcepub fn as_multi(&self) -> &MultiValueManagedVec<M, T>
pub fn as_multi(&self) -> &MultiValueManagedVec<M, T>
Creates a reference to and identical object, but one which behaves like a multi-value-vec.
Trait Implementations§
source§impl<M, T> Clone for ManagedVec<M, T>
impl<M, T> Clone for ManagedVec<M, T>
source§impl<M, T> Debug for ManagedVec<M, T>
impl<M, T> Debug for ManagedVec<M, T>
source§impl<M, T> Default for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
impl<M, T> Default for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
source§impl<M, T> From<&ManagedVec<M, T>> for MultiValueEncoded<M, T>
impl<M, T> From<&ManagedVec<M, T>> for MultiValueEncoded<M, T>
source§fn from(v: &ManagedVec<M, T>) -> Self
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,
impl<M> From<ManagedVec<M, ManagedBuffer<M>>> for ManagedArgBuffer<M>where
M: ManagedTypeApi,
source§fn from(data: ManagedVec<M, ManagedBuffer<M>>) -> Self
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>
impl<M, T> From<ManagedVec<M, T>> for MultiValueEncoded<M, T>
source§fn from(v: ManagedVec<M, T>) -> Self
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,
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
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,
impl<M, T> From<ManagedVec<M, T>> for MultiValueManagedVecCounted<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
source§fn from(v: ManagedVec<M, T>) -> Self
fn from(v: ManagedVec<M, T>) -> Self
Converts to this type from the input type.
source§impl<M, T, I> From<Vec<I>> for ManagedVec<M, T>
impl<M, T, I> From<Vec<I>> for ManagedVec<M, T>
source§impl<M, V> FromIterator<V> for ManagedVec<M, V>where
M: ManagedTypeApi,
V: ManagedVecItem,
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
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,
impl<'a, M, T> IntoIterator for &'a ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
source§impl<M, T> ManagedType<M> for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
impl<M, T> ManagedType<M> for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
type OwnHandle = <M as HandleTypeInfo>::ManagedBufferHandle
fn get_handle(&self) -> M::ManagedBufferHandle
source§fn transmute_from_handle_ref(handle_ref: &M::ManagedBufferHandle) -> &Self
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.
fn get_raw_handle(&self) -> RawHandle
fn as_ref(&self) -> ManagedRef<'_, M, Self>
source§impl<M, T> ManagedVecItem for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
impl<M, T> ManagedVecItem for ManagedVec<M, T>where
M: ManagedTypeApi,
T: ManagedVecItem,
source§const PAYLOAD_SIZE: usize = 4usize
const PAYLOAD_SIZE: usize = 4usize
Size of the data stored in the underlying
ManagedBuffer.source§const SKIPS_RESERIALIZATION: bool = false
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>>
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
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>
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
fn to_byte_writer<R, Writer: FnMut(&[u8]) -> R>(&self, writer: Writer) -> R
source§impl<M, T> NestedDecode for ManagedVec<M, T>
impl<M, T> NestedDecode for ManagedVec<M, T>
source§fn dep_decode_or_handle_err<I, H>(
input: &mut I,
h: H
) -> Result<Self, H::HandledErr>where
I: NestedDecodeInput,
H: DecodeErrorHandler,
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,
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>
impl<M, T> NestedEncode for ManagedVec<M, T>
source§fn dep_encode_or_handle_err<O, H>(
&self,
dest: &mut O,
h: H
) -> Result<(), H::HandledErr>where
O: NestedEncodeOutput,
H: EncodeErrorHandler,
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,
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 for ManagedVec<M, T>
impl<M, T> PartialEq for ManagedVec<M, T>
source§impl<M, T> TopDecode for ManagedVec<M, T>
impl<M, T> TopDecode for ManagedVec<M, T>
source§fn top_decode_or_handle_err<I, H>(input: I, h: H) -> Result<Self, H::HandledErr>where
I: TopDecodeInput,
H: DecodeErrorHandler,
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,
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>
impl<M, T> TopEncode for ManagedVec<M, T>
source§fn top_encode_or_handle_err<O, H>(
&self,
output: O,
h: H
) -> Result<(), H::HandledErr>where
O: TopEncodeOutput,
H: EncodeErrorHandler,
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,
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,
impl<M> TopEncodeMultiOutput for ManagedVec<M, ManagedBuffer<M>>where
M: ManagedTypeApi,
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,
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>
impl<M, T> TypeAbi for ManagedVec<M, T>
source§fn provide_type_descriptions<TDC: TypeDescriptionContainer>(
accumulator: &mut TDC
)
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.
impl<M, T> Eq for ManagedVec<M, T>
Auto Trait Implementations§
impl<M, T> CodecFromSelf for ManagedVec<M, T>where
T: CodecFromSelf,
impl<M, T> RefUnwindSafe for ManagedVec<M, T>
impl<M, T> Send for ManagedVec<M, T>
impl<M, T> Sync for ManagedVec<M, T>
impl<M, T> Unpin for ManagedVec<M, T>
impl<M, T> UnwindSafe for ManagedVec<M, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> SCCodec for Twhere
T: TopEncode,
impl<T> SCCodec for Twhere
T: TopEncode,
fn fmt<F>(&self, f: &mut F)where
F: FormatByteReceiver,
source§impl<T> TopDecodeMulti for Twhere
T: TopDecode,
impl<T> TopDecodeMulti for Twhere
T: TopDecode,
source§const IS_SINGLE_VALUE: bool = true
const IS_SINGLE_VALUE: bool = true
Used to optimize single value loading of endpoint arguments.
fn multi_decode_or_handle_err<I, H>(
input: &mut I,
h: H
) -> Result<T, <H as DecodeErrorHandler>::HandledErr>where
I: TopDecodeMultiInput,
H: DecodeErrorHandler,
fn multi_decode<I>(input: &mut I) -> Result<Self, DecodeError>where
I: TopDecodeMultiInput,
source§impl<T> TopDecodeMultiLength for T
impl<T> TopDecodeMultiLength for T
source§impl<T> TopEncodeMulti for Twhere
T: TopEncode,
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,
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,
fn multi_encode<O>(&self, output: &mut O) -> Result<(), EncodeError>where
O: TopEncodeMultiOutput,
Attempt to serialize the value to ouput.