multiversx_sc_snippets::imports

Trait ManagedVecItem

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

    const SKIPS_RESERIALIZATION: bool;

    // Required methods
    fn read_from_payload(payload: &Self::PAYLOAD) -> Self;
    unsafe fn borrow_from_payload<'a>(payload: &Self::PAYLOAD) -> Self::Ref<'a>;
    fn save_to_payload(self, payload: &mut Self::PAYLOAD);

    // 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 read_from_payload(payload: &Self::PAYLOAD) -> Self

Parses given bytes as a an owned object.

Source

unsafe fn borrow_from_payload<'a>(payload: &Self::PAYLOAD) -> 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 save_to_payload(self, payload: &mut Self::PAYLOAD)

Converts the object into 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§

impl ManagedVecItem for i32

Source§

impl ManagedVecItem for i64

Source§

impl ManagedVecItem for u8

Source§

impl ManagedVecItem for u16

Source§

impl ManagedVecItem for u32

Source§

impl ManagedVecItem for u64

Source§

impl ManagedVecItem for usize

Source§

impl<T> ManagedVecItem for Option<T>

Implementors§

Source§

impl ManagedVecItem for EsdtLocalRole

Source§

impl ManagedVecItem for EsdtTokenType

Source§

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

Source§

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

Source§

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

Source§

impl<M> ManagedVecItem for EgldOrEsdtTokenPayment<M>
where M: ManagedTypeApi,

Source§

impl<M> ManagedVecItem for EgldOrEsdtTokenPaymentMultiValue<M>
where M: ManagedTypeApi,

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

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<T1, T2> ManagedVecItem for MultiValue2<T1, T2>

Source§

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