[][src]Struct rfc::core::convert::transmute::options::NeglectAlignment

pub struct NeglectAlignment;

Neglect the static alignment check.

By default, TransmuteFrom and TransmuteInto are only implemented for references when the minimum alignment of the destination's referent type is no greater than the minimum alignment of the source's referent type. The NeglectAlignment option disables this requirement.

By using the NeglectAlignment option, you are committing to ensure that the transmuted reference satisfies the alignment requirements of the destination's referent type. For instance:

/// Try to convert a `&T` into `&U`.
///
/// This produces `None` if the referent isn't appropriately
/// aligned, as required by the destination type.
pub fn try_cast_ref<'t, 'u, T, U>(src: &'t T) -> Option<&'u U>
where
    &'t T: TransmuteInto<&'u U, NeglectAlignment>,
{
    if (src as *const T as usize) % align_of::<U>() != 0 {
        None
    } else {
        // Safe because we dynamically enforce the alignment
        // requirement, whose static check we chose to neglect.
        Some(unsafe { src.unsafe_transmute_into() })
    }
}

Trait Implementations

impl TransmuteOptions for NeglectAlignment[src]

Auto Trait Implementations

impl RefUnwindSafe for NeglectAlignment

impl Send for NeglectAlignment

impl Sync for NeglectAlignment

impl Unpin for NeglectAlignment

impl UnwindSafe for NeglectAlignment

Blanket Implementations

impl<Lhs, Rhs, Neglect> AlignEq<Rhs, Neglect> for Lhs where
    Lhs: AlignLtEq<Rhs, ()>,
    Neglect: TransmuteOptions,
    Rhs: AlignLtEq<Lhs, ()>, 
[src]

impl<Lhs, Rhs, Neglect> AlignLtEq<Rhs, Neglect> for Lhs where
    Neglect: TransmuteOptions,
    &'a [Lhs; 0]: for<'a> TransmuteFrom<&'a [Rhs; 0], Neglect>, 
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Src, Dst, Neglect> CastInto<Dst, Neglect> for Src where
    Dst: CastFrom<Src, Neglect>,
    Neglect: CastOptions
[src]

impl<Neglect> CastOptions for Neglect where
    Neglect: SliceCastOptions
[src]

impl<Neglect> CastOptions for Neglect where
    Neglect: VecCastOptions
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Neglect> SliceCastOptions for Neglect where
    Neglect: TransmuteOptions
[src]

impl<T> TransmuteFrom<T, NeglectStability> for T[src]

impl<Src, Dst, Neglect> TransmuteInto<Dst, Neglect> for Src where
    Dst: TransmuteFrom<Src, Neglect> + ?Sized,
    Neglect: TransmuteOptions,
    Src: ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<Neglect> VecCastOptions for Neglect where
    Neglect: TransmuteOptions
[src]