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§
type TypeMarker: TypeMarker
Required Methods§
Sourceunsafe fn write(self, slot: &mut S)
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.
Sourcefn as_ref(result: &Self::Result) -> &ExternAny
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.