Function fat_type::convert_mut [−][src]
pub unsafe fn convert_mut<'a, R: FatMut<'a>, U>(thin: R) -> &'a mut Fat<R::T, U>
Expand description
Obtains a mutable reference by respecifying the type of the sized referent, which may be erased.
Safety
The safety of this operation depends on the types of R::U
and U
.
- If
R::U
isErased<T>
, then eitherU
must also beErased<T>
or the un-erased type ofR::U
must be safe intotransmute
toU
and vice-versa. - If
R::U
is an un-erased type, then eitherU
must beErased<T>
orR::U
must be safe totransmute
intoU
and vice-versa.
The transmutation requirements above are bijective because the associated metadata is unmodified and remains that of the un-erased type.
If U
is Erased<T>
then the returned mutable reference, which is of
type &mut Fat<T>
, must not be used to create a dynamically incoherent
value. The following problematic operations can create such values because
the referent is omitted from most operations due to erasure. The Mut<T>
type can be used to create a safe wrapper around the reference.
Problematic Operations
- move operations on owned values are problematic because the referent
is not moved. Note that implicit copying will not occur because
Erased<T>
is notCopy
. - copy functions such as
core::ptr::copy
andcore::ptr::read
are problematic because the referent will be omitted from any copies. - swap functions such as
core::mem::swap
are problematic because the metadata will be swapped but the referent will not. - write functions such as
core::ptr::write
are problematic because the referent will not be written. - replace functions such as
core::mem::replace
are problematic because the referent will neither be replaced nor returned. - Dropping a
Fat<T>
will not drop its referent. This is generally not desirable and may interact poorly with the Drop Guarantee. - Deallocating a
Fat<T>
which was allocated as aFat<T, U>
causes immediate undefined behavior because its layout omits the referent. Deallocation can be performed manually or by types such asBox
,Rc
,Arc
, and the standard collections. To safely deallocate, useget_layout
to obtain the correctLayout
.
Safe Operations
All operations defined in fat_type
are guaranteed to maintain dynamic
coherence if their arguments are valid and dynamically coherent, except
where explicitly documented otherwise.