Prove retained casts require unsafe

This commit is contained in:
2026-07-31 04:27:35 +02:00
parent c645bb5f79
commit 2c07b2aada
+7
View File
@@ -152,6 +152,13 @@ impl TypeErasedVec {
/// Matching size alone is insufficient because the allocation must also have
/// the alignment required by `T`. The caller must additionally ensure that
/// every existing element is valid as `T` and can be soundly dropped as `T`.
///
/// ```compile_fail
/// use type_erased_vec_capacity::TypeErasedVec;
///
/// let mut erased = TypeErasedVec::new(vec![0_u32]);
/// let _guard = erased.cast_type::<i32>();
/// ```
pub unsafe fn cast_type<T: 'static>(&mut self) -> ContentGuard<'_, T> {
debug_assert_eq!(self.layout, Layout::new::<T>());