pub unsafe trait TempRepr {
type Shared<'a>
where Self: 'a;
// Required methods
unsafe fn new_temp(obj: Self::Shared<'_>) -> Self;
fn get(&self) -> Self::Shared<'_>;
}
Expand description
A trait that specifies that a type is a “temporary representation” of another type, where that
other type can depend on a lifetime (via GATs). The standard example is that a raw pointer can
be regarded as a temporary representation of a reference. The trait implementation for tuples
generalizes this to combinations of more than one pointer/reference, the trait implementation
for Option
extends it to optional references, etc.
Every type implementing TempRepr
can be used in TempInst
, which provides a safe API
around the temporary representation.
Rather than implementing this trait directly, it is recommended to do so by defining a mapping
to and from built-in types, using the safe trait mapped::HasTempRepr
.
§Safety
-
The implementation of the trait must ensure that
new_temp<'a>
followed byget<'b>
cannot cause undefined behavior when'a: 'b
. (This essentially restrictsShared<'a>
to types that are covariant in'a
.) -
The above must also hold if a (legal) cast was applied to the result of
new_temp
.
Required Associated Types§
The type that Self
is a temporary representation of. May contain shared references of
lifetime 'a
.
Required Methods§
Sourceunsafe fn new_temp(obj: Self::Shared<'_>) -> Self
unsafe fn new_temp(obj: Self::Shared<'_>) -> Self
Converts the given object to its temporary representation.
§Safety
The caller must ensure that the returned object does not outlive the lifetime argument of
obj
, and that TempReprMut::get_mut
or TempReprMut::get_mut_pinned
is never called
on the result.
(Exception: see the caveat in the safety rules of TempReprMutChk
.)
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.