Trait multiversx_sc::types::ManagedVecItem
source · pub trait ManagedVecItem: 'static {
type Ref<'a>: Borrow<Self>;
const PAYLOAD_SIZE: usize;
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 to_byte_writer<R, Writer: FnMut(&[u8]) -> R>(&self, writer: Writer) -> R;
}
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 Types§
sourcetype Ref<'a>: Borrow<Self>
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 Associated Constants§
sourceconst PAYLOAD_SIZE: usize
const PAYLOAD_SIZE: usize
Size of the data stored in the underlying ManagedBuffer
.
sourceconst SKIPS_RESERIALIZATION: bool
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 Methods§
sourcefn 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.
sourceunsafe 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.
Safety
In certain cases this involves practically disregarding the lifetimes, hence it is unsafe.