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§
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 Associated Types§
Sourcetype PAYLOAD: ManagedVecItemPayload
type PAYLOAD: ManagedVecItemPayload
Type managing the underlying binary representation in a ManagedVec..
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 Methods§
Sourcefn read_from_payload(payload: &Self::PAYLOAD) -> Self
fn read_from_payload(payload: &Self::PAYLOAD) -> Self
Parses given bytes as a an owned object.
Sourceunsafe fn borrow_from_payload<'a>(payload: &Self::PAYLOAD) -> Self::Ref<'a>
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.
Sourcefn save_to_payload(self, payload: &mut Self::PAYLOAD)
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§
fn payload_size() -> usize
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.