pub unsafe trait TempReprMut: TempRepr {
type Mutable<'a>
where Self: 'a;
// Required methods
unsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self;
fn get_mut(&mut self) -> Self::Mutable<'_>;
fn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>;
}
Expand description
An extension of TempRepr
that adds support for mutable references.
If the represented type has no special “mutable” variant, the AlwaysShared
marker trait can
be used to implement TempReprMut
identically to TempRepr
.
§Safety
In addition to the requirements of TempRepr
, the implementation needs to ensure the
following properties.
-
new_temp_mut<'a>
followed byget_mut<'b>
orget_mut_pinned<'b>
must not cause undefined behavior when'a: 'b
and'b
does not overlap with any other lifetime passed toget
orget_mut
orget_mut_pinned
. -
new_temp_mut<'a>
followed byget<'b>
must not cause undefined behavior when'a: 'b
and'b
does not overlap with any lifetime passed toget_mut
orget_mut_pinned
. -
The pinning projections that are implemented as part of
get_mut_pinned
in this crate, e.g. for tuples, must be safe when the type is the target of such a projection. (This is usually trivial, and e.g.Option::as_pin_mut
already exists in the standard library, but technically it is not automatically the case for tuples at the moment.) -
The above must also hold if a (legal) cast was applied to the result of
new_temp_mut
.
Required Associated Types§
Required Methods§
Sourceunsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self
unsafe fn new_temp_mut(obj: Self::Mutable<'_>) -> Self
Converts the given object to a temporary representation without a lifetime parameter.
§Safety
The caller must ensure that the returned object does not outlive the lifetime argument of
obj
.
(Exception: see the caveat in the safety rules of TempReprMutChk
.)
Sourcefn get_mut(&mut self) -> Self::Mutable<'_>
fn get_mut(&mut self) -> Self::Mutable<'_>
Converts from a mutable reference to the temporary representation back to the original type, with a restricted lifetime.
Sourcefn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>
fn get_mut_pinned(self: Pin<&mut Self>) -> Self::Mutable<'_>
Like TempReprMut::get_mut
, but takes a pinned mutable reference to Self
.
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.