multiversx_sc::types

Trait ManagedType

Source
pub trait ManagedType<M: ManagedTypeApi>: Sized {
    type OwnHandle: HandleConstraints;

    // Required methods
    fn get_handle(&self) -> Self::OwnHandle;
    unsafe fn forget_into_handle(self) -> Self::OwnHandle;
    fn transmute_from_handle_ref(handle_ref: &Self::OwnHandle) -> &Self;
    fn transmute_from_handle_ref_mut(
        handle_ref: &mut Self::OwnHandle,
    ) -> &mut Self;

    // Provided methods
    fn get_raw_handle(&self) -> RawHandle { ... }
    fn as_ref(&self) -> ManagedRef<'_, M, Self> { ... }
}
Expand description

Commonalities between all managed types.

Required Associated Types§

Required Methods§

Source

fn get_handle(&self) -> Self::OwnHandle

Source

unsafe fn forget_into_handle(self) -> Self::OwnHandle

Forgets current object (does not run destructor), but extracts the handle.

The handle remains an owned object, so the handle’s destructor will run later, when dropped.

§Safety

Destructures the object, without running a constructor.

To avoid a memory leak, it is necessary for the object to be later reconstructed from handle and its destructor run.

It is designed to be used ManagedVec and ManagedOption, where items are dropped later, together with their container.

Source

fn transmute_from_handle_ref(handle_ref: &Self::OwnHandle) -> &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 transmute_from_handle_ref_mut(handle_ref: &mut Self::OwnHandle) -> &mut Self

Provided Methods§

Source

fn get_raw_handle(&self) -> RawHandle

Source

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

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.

Implementors§

Source§

impl<A> ManagedType<A> for StorageKey<A>
where A: ManagedTypeApi + ErrorApi + 'static,

Source§

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

Source§

impl<M> ManagedType<M> for ManagedArgBuffer<M>
where M: ManagedTypeApi + 'static,

Source§

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

Source§

impl<M, T> ManagedType<M> for MultiValueManagedVec<M, T>

Source§

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

Source§

impl<M: ManagedTypeApi> ManagedType<M> for BigFloat<M>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<M: ManagedTypeApi> ManagedType<M> for ManagedMap<M>

Source§

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