From 0b72219db32bd0cc84f336183efad89c56fcf442 Mon Sep 17 00:00:00 2001 From: soruh Date: Fri, 31 Jul 2026 03:27:08 +0200 Subject: [PATCH] Tighten internal visibility and naming --- src/guard.rs | 6 +++--- src/parts.rs | 20 ++++++++++---------- src/vtable.rs | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/guard.rs b/src/guard.rs index 56f9069..b59a9d4 100644 --- a/src/guard.rs +++ b/src/guard.rs @@ -37,11 +37,11 @@ impl<'vec, T> ContentGuard<'vec, T> { /// /// The guard remains usable with an empty, zero-capacity vector. pub fn take(&mut self) -> Vec { - let erased = std::mem::replace(self.erased, (self.reerase)(Vec::new())); - let erased = ManuallyDrop::new(erased); + let old_erased = std::mem::replace(self.erased, (self.reerase)(Vec::new())); + let old_erased = ManuallyDrop::new(old_erased); // SAFETY: The erased pointer, length, and capacity are valid for a Vec. // ManuallyDrop prevents the old TypeErasedVec from double-freeing the allocation. - unsafe { erased.parts.into_vec() } + unsafe { old_erased.parts.into_vec() } } /// Calls `function` with the underlying vector and then type-erases it again. diff --git a/src/parts.rs b/src/parts.rs index e23ef7f..a4eca95 100644 --- a/src/parts.rs +++ b/src/parts.rs @@ -1,34 +1,34 @@ use std::ptr::NonNull; #[derive(Clone, Copy)] -pub(crate) struct VecParts { - pub ptr: NonNull, - pub len: usize, - pub cap: usize, +pub(super) struct VecParts { + pub(super) ptr: NonNull, + pub(super) len: usize, + pub(super) cap: usize, } impl VecParts { - pub(crate) fn from_vec(vec: Vec) -> Self { - let (ptr, len, cap) = vec.into_raw_parts(); + pub(super) fn from_vec(vec: Vec) -> Self { + let (raw_ptr, len, cap) = vec.into_raw_parts(); // SAFETY: Vec guarantees its underlying pointer is non-null. - let ptr = unsafe { NonNull::new_unchecked(ptr.cast::()) }; + let ptr = unsafe { NonNull::new_unchecked(raw_ptr.cast::()) }; Self { ptr, len, cap } } - pub(crate) unsafe fn into_vec(self) -> Vec { + pub(super) unsafe fn into_vec(self) -> Vec { unsafe { Vec::from_raw_parts(self.ptr.as_ptr().cast::(), self.len, self.cap) } } #[must_use] - pub(crate) unsafe fn as_slice(&self) -> &[T] { + pub(super) unsafe fn as_slice(&self) -> &[T] { // SAFETY: Ensured by the caller unsafe { std::slice::from_raw_parts(self.ptr.as_ptr().cast(), self.len) } } #[must_use] - pub(crate) unsafe fn as_slice_mut(&mut self) -> &mut [T] { + pub(super) unsafe fn as_slice_mut(&mut self) -> &mut [T] { // SAFETY: Ensured by the caller unsafe { std::slice::from_raw_parts_mut(self.ptr.as_ptr().cast(), self.len) } } diff --git a/src/vtable.rs b/src/vtable.rs index 1b38c9f..6ac9c16 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -1,16 +1,16 @@ use crate::VecParts; -pub(crate) struct TypeErasedVecVtable { +pub(super) struct TypeErasedVecVtable { /// Function pointer to reserve additional capacity in the underlying Vec - pub reserve: unsafe fn(parts: &mut VecParts, additional: usize), + pub(super) reserve: unsafe fn(parts: &mut VecParts, additional: usize), /// Function pointer to clear the underlying capacity of its old elements - pub clear: unsafe fn(parts: &mut VecParts), + pub(super) clear: unsafe fn(parts: &mut VecParts), /// Function pointer to the original type's drop logic. - pub drop: unsafe fn(parts: VecParts), + pub(super) drop: unsafe fn(parts: VecParts), } impl TypeErasedVecVtable { - pub fn new() -> Self { + pub(super) fn new() -> Self { unsafe fn drop_vec(parts: VecParts) { // SAFETY: We reconstruct the Vec to let its Drop impl handle deallocation. _ = unsafe { parts.into_vec::() };