Trait abi_stable::pointer_trait::TransmuteElement
source · pub trait TransmuteElement {
// Provided method
unsafe fn transmute_element<T>(
self,
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr
where Self: CanTransmuteElement<T> { ... }
}
Expand description
Allows transmuting pointers to point to a different type.
Provided Methods§
sourceunsafe fn transmute_element<T>(
self,
) -> <Self as CanTransmuteElement<T>>::TransmutedPtrwhere
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self,
) -> <Self as CanTransmuteElement<T>>::TransmutedPtrwhere
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer..
§Safety
Callers must ensure that it is valid to convert from a pointer to Self::PtrTarget
to a pointer to T
, and then use the pointed-to data.
For example:
It is undefined behavior to create unaligned references ,
therefore transmuting from &u8
to &u16
is UB
if the caller does not ensure that the reference is aligned to a multiple of 2 address.
§Example
use abi_stable::{
pointer_trait::TransmuteElement,
std_types::RBox,
};
let signed:RBox<u32>=unsafe{
RBox::new(1_i32)
.transmute_element::<u32>()
};