// This is for when we're implementing Yoke on a complex type such that it's not // obvious to the compiler that the lifetime is covariant // // Safety: the caller of this macro must ensure that `Self` is indeed covariant in 'a.
macro_rules! unsafe_complex_yoke_impl {
() => { fn transform(&'a self) -> &'a Self::Output { // Safety: equivalent to casting the lifetime. Macro caller ensures covariance. unsafe { mem::transmute(self) }
}
fn transform_owned(self) -> Self::Output {
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); // Safety: equivalent to casting the lifetime. Macro caller ensures covariance. unsafe { let ptr: *constSelf::Output = (&selfas *constSelf).cast(); let _ = ManuallyDrop::new(self);
ptr::read(ptr)
}
}
unsafefn make(from: Self::Output) -> Self {
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); let ptr: *constSelf = (&from as *constSelf::Output).cast(); let _ = ManuallyDrop::new(from); // Safety: `ptr` is certainly valid, aligned and points to a properly initialized value, as // it comes from a value that was moved into a ManuallyDrop. unsafe { ptr::read(ptr) }
}
fn transform_mut<F>(&'a mut self, f: F) where
F: 'static + for<'b> FnOnce(&'b mut Self::Output),
{ // Cast away the lifetime of Self // Safety: this is equivalent to f(transmute(self)), and the documentation of the trait // method explains why doing so is sound. unsafe { f(mem::transmute::<&'a mut Self, &'a mutSelf::Output>(self)) }
}
};
}
// Safety: since T implements Yokeable<'a>, Option<T<'b>> must be covariant on 'b or the Yokeable // implementation on T would be unsound. unsafeimpl<'a, T: 'static + for<'b> Yokeable<'b>> Yokeable<'a> for Option<T> { type Output = Option<<T as Yokeable<'a>>::Output>;
unsafe_complex_yoke_impl!();
}
// Safety: since T1, T2 implement Yokeable<'a>, (T1<'b>, T2<'b>) must be covariant on 'b or the Yokeable // implementation on T would be unsound. unsafeimpl<'a, T1: 'static + for<'b> Yokeable<'b>, T2: 'static + for<'b> Yokeable<'b>> Yokeable<'a> for (T1, T2)
{ type Output = (<T1 as Yokeable<'a>>::Output, <T2 as Yokeable<'a>>::Output);
unsafe_complex_yoke_impl!();
}
// Safety: since T implements Yokeable<'a>, [T<'b>; N] must be covariant on 'b or the Yokeable // implementation on T would be unsound. unsafeimpl<'a, T: 'static + for<'b> Yokeable<'b>, const N: usize> Yokeable<'a> for [T; N] { type Output = [<T as Yokeable<'a>>::Output; N];
unsafe_complex_yoke_impl!();
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.