Trait proc_bitfield::UnsafeFrom

source ·
pub trait UnsafeFrom<T> {
    // Required method
    unsafe fn unsafe_from(_: T) -> Self;
}
Expand description

Unsafe equivalent of From.

Used to do unsafe value-to-value conversions while consuming the input value. It is the reciprocal of UnsafeInto.

One should always prefer implementing UnsafeFrom over UnsafeInto because implementing UnsafeFrom automatically provides one with an implementation of UnsafeInto thanks to the blanket implementation.

Prefer using UnsafeInto over using UnsafeFrom when specifying trait bounds on a generic function. This way, types that directly implement UnsafeInto can be used as arguments as well.

Note: This trait must not fail. The UnsafeFrom trait is intended for unsafe but perfect conversions. If the conversion can fail or is not perfect, use TryFrom.

§Generic Implementations

  • UnsafeFrom<T> for U implies UnsafeInto<U> for T
  • UnsafeFrom, like From, is reflexive, which means that UnsafeFrom<T> for T is implemented
  • From<T> for U implies UnsafeFrom<T> for U
  • Into<U> for T implies UnsafeFrom<T> for U

Required Methods§

source

unsafe fn unsafe_from(_: T) -> Self

Unsafely converts to this type from the input type.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl UnsafeFrom<SpuriouslyFailingU8> for u8

source§

unsafe fn unsafe_from(other: SpuriouslyFailingU8) -> Self

source§

impl UnsafeFrom<U16> for u8

source§

unsafe fn unsafe_from(other: U16) -> Self

Implementors§