Trait Slot

Source
pub unsafe trait Slot<S>
where Self: Sized,
{ type TypeMarker: TypeMarker; type Result: Sized; // Required methods unsafe fn write(self, slot: &mut S); unsafe fn read(slot: S) -> Self::Result; fn as_ref(result: &Self::Result) -> &ExternAny; }
Expand description

Types that can be used safely for slots of type T

For example, if we have an API that is expecting a string, we would implement this trait for string types.

Required Associated Types§

Source

type TypeMarker: TypeMarker

Source

type Result: Sized

Output type of reading from a slot previously written to (can be anything)

Required Methods§

Source

unsafe fn write(self, slot: &mut S)

Writes self into slot, doing as little work as needed

Work should be deferred to read, if possible.

§Safety

Implementors must store a value into slot, that read can read back later. read is allowed to rely on the fact that something has been written.

It may be undesireable to call write twice on the same slot, but even with that, there is no strict requirement that callers only call write once.

Source

unsafe fn read(slot: S) -> Self::Result

Reads back what was written to slot in write, then processes it into the read output type as necessary

§Safety

Implementors can assume that write has been called on slot and a value has been written as expected.

Callers must call write on this slot first, before passing it to this function.

Source

fn as_ref(result: &Self::Result) -> &ExternAny

Converts the read output type into a reference of type &ExternAny

This function is used so implementors can return non reference types. Trait consumers would then take ownership of the provided output, and use this function to get a reference type &ExternAny from it.

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§