Trait castaway::LifetimeFree

source ·
pub unsafe trait LifetimeFree { }
Expand description

Marker trait for types that do not contain any lifetime parameters. Such types are safe to cast from non-static type parameters if their types are equal.

This trait is used by cast! to determine what casts are legal on values without a 'static type constraint.

§Safety

When implementing this trait for a type, you must ensure that the type is free of any lifetime parameters. Failure to meet all of the requirements below may result in undefined behavior.

  • The type must be 'static.
  • The type must be free of lifetime parameters. In other words, the type must be an “owned” type and not contain any lifetime parameters.
  • All contained fields must also be LifetimeFree.

§Examples

use castaway::LifetimeFree;

struct Container<T>(T);

// UNDEFINED BEHAVIOR!!
// unsafe impl LifetimeFree for Container<&'static str> {}

// UNDEFINED BEHAVIOR!!
// unsafe impl<T> LifetimeFree for Container<T> {}

// This is safe.
unsafe impl<T: LifetimeFree> LifetimeFree for Container<T> {}

struct PlainOldData {
    foo: u8,
    bar: bool,
}

// This is also safe, since all fields are known to be `LifetimeFree`.
unsafe impl LifetimeFree for PlainOldData {}

Implementations on Foreign Types§

source§

impl LifetimeFree for bool

source§

impl LifetimeFree for char

source§

impl LifetimeFree for f32

source§

impl LifetimeFree for f64

source§

impl LifetimeFree for i8

source§

impl LifetimeFree for i16

source§

impl LifetimeFree for i32

source§

impl LifetimeFree for i64

source§

impl LifetimeFree for i128

source§

impl LifetimeFree for isize

source§

impl LifetimeFree for str

source§

impl LifetimeFree for u8

source§

impl LifetimeFree for u16

source§

impl LifetimeFree for u32

source§

impl LifetimeFree for u64

source§

impl LifetimeFree for u128

source§

impl LifetimeFree for ()

source§

impl LifetimeFree for usize

source§

impl LifetimeFree for String

source§

impl LifetimeFree for NonZeroI8

source§

impl LifetimeFree for NonZeroI16

source§

impl LifetimeFree for NonZeroI32

source§

impl LifetimeFree for NonZeroI64

source§

impl LifetimeFree for NonZeroI128

source§

impl LifetimeFree for NonZeroIsize

source§

impl LifetimeFree for NonZeroU8

source§

impl LifetimeFree for NonZeroU16

source§

impl LifetimeFree for NonZeroU32

source§

impl LifetimeFree for NonZeroU64

source§

impl LifetimeFree for NonZeroU128

source§

impl LifetimeFree for NonZeroUsize

source§

impl<T0: LifetimeFree> LifetimeFree for (T0,)

source§

impl<T0: LifetimeFree, T1: LifetimeFree> LifetimeFree for (T0, T1)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree> LifetimeFree for (T0, T1, T2)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree> LifetimeFree for (T0, T1, T2, T3)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree, T5: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4, T5)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree, T5: LifetimeFree, T6: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4, T5, T6)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree, T5: LifetimeFree, T6: LifetimeFree, T7: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4, T5, T6, T7)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree, T5: LifetimeFree, T6: LifetimeFree, T7: LifetimeFree, T8: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

source§

impl<T0: LifetimeFree, T1: LifetimeFree, T2: LifetimeFree, T3: LifetimeFree, T4: LifetimeFree, T5: LifetimeFree, T6: LifetimeFree, T7: LifetimeFree, T8: LifetimeFree, T9: LifetimeFree> LifetimeFree for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

source§

impl<T: LifetimeFree> LifetimeFree for Option<T>

source§

impl<T: LifetimeFree> LifetimeFree for [T]

source§

impl<T: LifetimeFree> LifetimeFree for Box<T>

source§

impl<T: LifetimeFree> LifetimeFree for Arc<T>

source§

impl<T: LifetimeFree> LifetimeFree for Vec<T>

source§

impl<T: LifetimeFree> LifetimeFree for Cell<T>

source§

impl<T: LifetimeFree> LifetimeFree for RefCell<T>

source§

impl<T: LifetimeFree> LifetimeFree for Wrapping<T>

source§

impl<T: LifetimeFree, E: LifetimeFree> LifetimeFree for Result<T, E>

source§

impl<T: LifetimeFree, const SIZE: usize> LifetimeFree for [T; SIZE]

Implementors§