Merge pull request #543 from pvdrz/remove-sealed-mod

Remove `sealed` module
This commit is contained in:
Alex Martens 2025-03-25 01:29:47 +00:00 committed by GitHub
commit b8245158b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 28 additions and 88 deletions

View File

@ -152,8 +152,9 @@ impl<T, const N: usize> Deque<T, N> {
/// static mut X: Deque<u8, 16> = Deque::new(); /// static mut X: Deque<u8, 16> = Deque::new();
/// ``` /// ```
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert N > 0 const {
crate::sealed::greater_than_0::<N>(); assert!(N > 0);
}
Self { Self {
phantom: PhantomData, phantom: PhantomData,

View File

@ -208,8 +208,9 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
/// ``` /// ```
#[inline] #[inline]
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert const {
crate::sealed::greater_than_0::<N>(); assert!(N > 0);
}
Self { Self {
phantom: PhantomData, phantom: PhantomData,

View File

@ -729,9 +729,10 @@ pub struct IndexMap<K, V, S, const N: usize> {
impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> { impl<K, V, S, const N: usize> IndexMap<K, V, BuildHasherDefault<S>, N> {
/// Creates an empty `IndexMap`. /// Creates an empty `IndexMap`.
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert const {
crate::sealed::greater_than_1::<N>(); assert!(N > 1);
crate::sealed::power_of_two::<N>(); assert!(N.is_power_of_two());
}
Self { Self {
build_hasher: BuildHasherDefault::new(), build_hasher: BuildHasherDefault::new(),
@ -1236,9 +1237,10 @@ where
S: Default, S: Default,
{ {
fn default() -> Self { fn default() -> Self {
// Const assert const {
crate::sealed::greater_than_1::<N>(); assert!(N > 1);
crate::sealed::power_of_two::<N>(); assert!(N.is_power_of_two());
}
Self { Self {
build_hasher: <_>::default(), build_hasher: <_>::default(),

View File

@ -221,8 +221,6 @@ pub mod spsc;
#[cfg(feature = "ufmt")] #[cfg(feature = "ufmt")]
mod ufmt; mod ufmt;
mod sealed;
/// Implementation details for macros. /// Implementation details for macros.
/// Do not use. Used for macros only. Not covered by semver guarantees. /// Do not use. Used for macros only. Not covered by semver guarantees.
#[doc(hidden)] #[doc(hidden)]

View File

@ -151,17 +151,13 @@ pub type MpMcQueue<T, const N: usize> = MpMcQueueInner<T, OwnedStorage<N>>;
pub type MpMcQueueView<T> = MpMcQueueInner<T, ViewStorage>; pub type MpMcQueueView<T> = MpMcQueueInner<T, ViewStorage>;
impl<T, const N: usize> MpMcQueue<T, N> { impl<T, const N: usize> MpMcQueue<T, N> {
const ASSERT: [(); 1] = [()];
/// Creates an empty queue /// Creates an empty queue
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert const {
crate::sealed::greater_than_1::<N>(); assert!(N > 1);
crate::sealed::power_of_two::<N>(); assert!(N.is_power_of_two());
assert!(N < UintSize::MAX as usize);
// Const assert on size. }
#[allow(clippy::no_effect)]
Self::ASSERT[(N >= (UintSize::MAX as usize)) as usize];
let mut cell_count = 0; let mut cell_count = 0;

View File

@ -1,59 +0,0 @@
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn smaller_than<const N: usize, const MAX: usize>() {
Assert::<N, MAX>::LESS;
}
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn greater_than_eq<const N: usize, const MIN: usize>() {
Assert::<N, MIN>::GREATER_EQ;
}
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn greater_than_eq_0<const N: usize>() {
Assert::<N, 0>::GREATER_EQ;
}
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn greater_than_0<const N: usize>() {
Assert::<N, 0>::GREATER;
}
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn greater_than_1<const N: usize>() {
Assert::<N, 1>::GREATER;
}
#[allow(dead_code, path_statements, clippy::no_effect)]
pub const fn power_of_two<const N: usize>() {
Assert::<N, 0>::GREATER;
Assert::<N, 0>::POWER_OF_TWO;
}
#[allow(dead_code)]
/// Const assert hack
pub struct Assert<const L: usize, const R: usize>;
#[allow(dead_code)]
impl<const L: usize, const R: usize> Assert<L, R> {
/// Const assert hack
pub const GREATER_EQ: usize = L - R;
/// Const assert hack
pub const LESS_EQ: usize = R - L;
/// Const assert hack
#[allow(clippy::erasing_op)]
pub const NOT_EQ: isize = 0 / (R as isize - L as isize);
/// Const assert hack
pub const EQ: usize = (R - L) + (L - R);
/// Const assert hack
pub const GREATER: usize = L - R - 1;
/// Const assert hack
pub const LESS: usize = R - L - 1;
/// Const assert hack
pub const POWER_OF_TWO: usize = 0 - (L & (L - 1));
}

View File

@ -237,8 +237,9 @@ macro_rules! impl_index_and_const_new {
/// Create a new linked list. /// Create a new linked list.
pub const fn $new_name() -> Self { pub const fn $new_name() -> Self {
// Const assert N < MAX const {
crate::sealed::smaller_than::<N, $max_val>(); assert!(N < $max_val);
}
let mut list = SortedLinkedList { let mut list = SortedLinkedList {
list: OwnedSortedLinkedListStorage { list: OwnedSortedLinkedListStorage {

View File

@ -143,8 +143,9 @@ pub type QueueView<T> = QueueInner<T, ViewStorage>;
impl<T, const N: usize> Queue<T, N> { impl<T, const N: usize> Queue<T, N> {
/// Creates an empty queue with a fixed capacity of `N - 1` /// Creates an empty queue with a fixed capacity of `N - 1`
pub const fn new() -> Self { pub const fn new() -> Self {
// Const assert N > 1 const {
crate::sealed::greater_than_1::<N>(); assert!(N > 1);
}
Queue { Queue {
head: AtomicUsize::new(0), head: AtomicUsize::new(0),

View File

@ -211,10 +211,9 @@ impl<T, const N: usize> Vec<T, N> {
/// If the length of the provided array is greater than the capacity of the /// If the length of the provided array is greater than the capacity of the
/// vector a compile-time error will be produced. /// vector a compile-time error will be produced.
pub fn from_array<const M: usize>(src: [T; M]) -> Self { pub fn from_array<const M: usize>(src: [T; M]) -> Self {
// Const assert M >= 0 const {
crate::sealed::greater_than_eq_0::<M>(); assert!(N >= M);
// Const assert N >= M }
crate::sealed::greater_than_eq::<N, M>();
// We've got to copy `src`, but we're functionally moving it. Don't run // We've got to copy `src`, but we're functionally moving it. Don't run
// any Drop code for T. // any Drop code for T.