multiversx_sc::types

Trait ManagedVecItem

Source
pub trait ManagedVecItem: 'static {
    type PAYLOAD: ManagedVecItemPayload;
    type Ref<'a>: Borrow<Self>;

    const SKIPS_RESERIALIZATION: bool;

    // Required methods
    fn from_byte_reader<Reader: FnMut(&mut [u8])>(reader: Reader) -> Self;
    unsafe fn from_byte_reader_as_borrow<'a, Reader: FnMut(&mut [u8])>(
        reader: Reader,
    ) -> Self::Ref<'a>;
    fn into_byte_writer<R, Writer: FnMut(&[u8]) -> R>(self, writer: Writer) -> R;

    // Provided method
    fn payload_size() -> usize { ... }
}
Expand description

Types that implement this trait can be items inside a ManagedVec. All these types need a payload, i.e a representation that gets stored in the underlying managed buffer. Not all data needs to be stored as payload, for instance for most managed types the payload is just the handle, whereas the mai ndata is kept by the VM.

Required Associated Constants§

Source

const SKIPS_RESERIALIZATION: bool

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).

Required Associated Types§

Source

type PAYLOAD: ManagedVecItemPayload

Type managing the underlying binary representation in a ManagedVec..

Source

type Ref<'a>: Borrow<Self>

Reference representation of the ManagedVec item.

Implementations:

  • For items with Copy semantics, it should be the type itself.
  • For managed types, ManagedRef does the job.
  • For any other types, Self is currently used, although this is technically unsafe.

TODO: wrap other types in readonly wrapper.

Required Methods§

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.

§Safety

In certain cases this involves practically disregarding the lifetimes, hence it is unsafe.

Source

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

Converts the object into bytes.

The output is processed by the writer lambda. The writer is provided by the caller. The callee will use it to pass on the bytes.

The method is used when instering (push, overwrite) into a ManagedVec.

Note that a destructor should not be called at this moment, since the ManagedVec will take ownership of the item.

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ManagedVecItem for bool

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<1>

Source§

type Ref<'a> = bool

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for i32

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<4>

Source§

type Ref<'a> = i32

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for i64

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<8>

Source§

type Ref<'a> = i64

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for u8

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<1>

Source§

type Ref<'a> = u8

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for u16

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<2>

Source§

type Ref<'a> = u16

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for u32

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<4>

Source§

type Ref<'a> = u32

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for u64

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<8>

Source§

type Ref<'a> = u64

Source§

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

Source§

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

Source§

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

Source§

impl ManagedVecItem for usize

Source§

const SKIPS_RESERIALIZATION: bool = true

Source§

type PAYLOAD = ManagedVecItemPayloadBuffer<4>

Source§

type Ref<'a> = usize

Source§

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

Source§

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

Source§

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

Source§

impl<T> ManagedVecItem for Option<T>

Source§

const SKIPS_RESERIALIZATION: bool = false

Source§

type PAYLOAD = <(u8, (T, ())) as ManagedVecItemNestedTuple>::PAYLOAD

Source§

type Ref<'a> = Option<T>

Source§

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

Source§

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

Source§

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

Implementors§

Source§

impl ManagedVecItem for EsdtLocalRole

Source§

impl ManagedVecItem for EsdtTokenType

Source§

impl<M, T> ManagedVecItem for ManagedOption<M, T>
where M: ManagedTypeApi, T: ManagedType<M> + 'static,

Source§

impl<M, T> ManagedVecItem for ManagedVec<M, T>

Source§

impl<M, T> ManagedVecItem for MultiValueManagedVecCounted<M, T>

Source§

impl<M, const N: usize> ManagedVecItem for ManagedByteArray<M, N>
where M: ManagedTypeApi,

Source§

impl<M: ManagedTypeApi> ManagedVecItem for BigInt<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for BigUint<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for EgldOrEsdtTokenIdentifier<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for EllipticCurve<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for EsdtTokenData<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for EsdtTokenPayment<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for EsdtTokenPaymentMultiValue<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for ManagedAddress<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for ManagedBuffer<M>

Source§

impl<M: ManagedTypeApi> ManagedVecItem for TokenIdentifier<M>

Source§

impl<T1, T2> ManagedVecItem for MultiValue2<T1, T2>

Source§

impl<T1, T2, T3> ManagedVecItem for MultiValue3<T1, T2, T3>

Source§

const SKIPS_RESERIALIZATION: bool = _

Source§

type PAYLOAD = <(T1, (T2, (T3, ()))) as ManagedVecItemNestedTuple>::PAYLOAD

Source§

type Ref<'a> = MultiValue3<T1, T2, T3>