Trait ReuseCastInto

Source
pub unsafe trait ReuseCastInto<T> { }
Expand description

A trait that indicates that a type can be safely cast into another type for the purpose of reusing a collection’s allocation.

§Safety

This trait is unsafe to implement because it allows for type transmutation through pointer casting. Implementers must guarantee that it is safe to transmute a container of Self (e.g., Vec<Self>) into a container of T (e.g., Vec<T>).

For this library, this is primarily used to change the lifetimes of references (e.g., from &'static str to &'a str), which is safe because the collection is cleared before it is used with the new type, and the new lifetimes are constrained by the guard’s lifetime.

For types with the same memory layout (e.g., primitive integers), this is also safe.

Implementations on Foreign Types§

Source§

impl ReuseCastInto<bool> for bool

Source§

impl ReuseCastInto<char> for char

Source§

impl ReuseCastInto<f32> for f32

Source§

impl ReuseCastInto<f64> for f64

Source§

impl ReuseCastInto<i8> for i8

Source§

impl ReuseCastInto<i16> for i16

Source§

impl ReuseCastInto<i32> for i32

Source§

impl ReuseCastInto<i64> for i64

Source§

impl ReuseCastInto<i128> for i128

Source§

impl ReuseCastInto<isize> for isize

Source§

impl ReuseCastInto<u8> for u8

Source§

impl ReuseCastInto<u16> for u16

Source§

impl ReuseCastInto<u32> for u32

Source§

impl ReuseCastInto<u64> for u64

Source§

impl ReuseCastInto<u128> for u128

Source§

impl ReuseCastInto<usize> for usize

Source§

impl ReuseCastInto<String> for String

Source§

impl<T> ReuseCastInto<Vec<T>> for Vec<T>

Source§

impl<T: ?Sized> ReuseCastInto<&T> for &T

Implementors§