[][src]Trait abi_stable::pointer_trait::TransmuteElement

pub trait TransmuteElement {
    unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr
    where
        Self: CanTransmuteElement<T>,
        Self::Target: Sized
, { ... } }

An extension trait which allows transmuting pointers to point to a different type.

Safety for callers

Callers must ensure that:

  • References to T are compatible with references to Self::Target.

Provided methods

unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
    Self: CanTransmuteElement<T>,
    Self::Target: Sized

Transmutes the element type of this pointer..

Safety

Callers must ensure that it is valid to convert from a pointer to Self::Referent to a pointer to T .

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 was a multiple of 2.

Example

use abi_stable::{
    pointer_trait::TransmuteElement,
    std_types::RBox,
};

let signed:RBox<u32>=unsafe{
    RBox::new(1_i32)
        .transmute_element::<u32>()
};
Loading content...

Implementors

impl<This: ?Sized> TransmuteElement for This[src]

Loading content...