Update safety comments for case.
This commit is contained in:
+8
-4
@@ -83,8 +83,10 @@ impl TypeErasedVec {
|
||||
/// Casts the present elements to the new type without calling their destructor.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the existing elements can be safely transmuted
|
||||
/// into the new type `T` and that dropping them as `T` is sound.
|
||||
/// `T` must have exactly the same [`Layout`] as the erased element type.
|
||||
/// 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`.
|
||||
pub unsafe fn cast_type<T>(&mut self) -> ContentGuard<'_, T> {
|
||||
debug_assert_eq!(self.layout, Layout::new::<T>());
|
||||
|
||||
@@ -171,8 +173,10 @@ impl TypeErasedVec {
|
||||
/// Convert the capacity of the erased `Vec` into a `Vec<T>`.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the existing elements can be safely transmuted
|
||||
/// into the new type `T` and that dropping them as `T` is sound.
|
||||
/// `T` must have exactly the same [`Layout`] as the erased element type.
|
||||
/// 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`.
|
||||
#[must_use]
|
||||
pub unsafe fn cast_into_vec<T>(mut self) -> Vec<T> {
|
||||
unsafe { self.cast_type::<T>() }.take()
|
||||
|
||||
+10
-4
@@ -58,8 +58,11 @@ macro_rules! define_thread_safe_erased_vec {
|
||||
/// Access the erased vector as `T` without clearing its elements.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the existing elements can be safely
|
||||
/// transmuted into `T` and that dropping them as `T` is sound.
|
||||
/// `T` must have exactly the same [`Layout`] as the erased element
|
||||
/// type. 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`.
|
||||
pub unsafe fn cast_type<T>(&mut self) -> ContentGuard<'_, T>
|
||||
where
|
||||
T: $first_bound $(+ $remaining_bound)*,
|
||||
@@ -128,8 +131,11 @@ macro_rules! define_thread_safe_erased_vec {
|
||||
/// Convert the erased vector into a `Vec<T>` without clearing it.
|
||||
///
|
||||
/// # Safety
|
||||
/// The caller must ensure that the existing elements can be safely
|
||||
/// transmuted into `T` and that dropping them as `T` is sound.
|
||||
/// `T` must have exactly the same [`Layout`] as the erased element
|
||||
/// type. 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`.
|
||||
#[must_use]
|
||||
pub unsafe fn cast_into_vec<T>(self) -> Vec<T>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user