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>(reader: Reader) -> Self
       where Reader: FnMut(&mut [u8]);
    unsafe fn from_byte_reader_as_borrow<'a, Reader>(
        reader: Reader,
    ) -> Self::Ref<'a>
       where Reader: FnMut(&mut [u8]);
    fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
       where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> Self
where Reader: FnMut(&mut [u8]),

Parses given bytes as a an owned object.

Source

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

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 to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> R,

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>(reader: Reader) -> bool
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> i32
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> i64
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> u8
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> u16
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> u32
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> u64
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> usize
where Reader: FnMut(&mut [u8]),

Source§

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

Source§

fn to_byte_writer<R, Writer>(&self, writer: Writer) -> R
where Writer: FnMut(&[u8]) -> 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>(reader: Reader) -> Option<T>
where Reader: FnMut(&mut [u8]),

Source§

unsafe fn from_byte_reader_as_borrow<'a, Reader>( reader: Reader, ) -> <Option<T> as ManagedVecItem>::Ref<'a>
where Reader: FnMut(&mut [u8]),

Source§

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

Implementors§

Source§

impl ManagedVecItem for DcdtLocalRole

Source§

impl ManagedVecItem for DcdtTokenType

Source§

impl ManagedVecItem for DebugHandle

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 DcdtTokenData<M>
where M: ManagedTypeApi,

Source§

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

Source§

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

Source§

impl<M> ManagedVecItem for EllipticCurve<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 RewaOrDcdtTokenIdentifier<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, const N: usize> ManagedVecItem for ManagedByteArray<M, N>
where M: ManagedTypeApi,