Remove sealed module

This commit is contained in:
Christian Poveda 2025-03-24 14:57:07 -05:00
parent bfc95984f3
commit 18446d780f
No known key found for this signature in database
GPG Key ID: 3B422F347D81A9E8
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();
/// ```
pub const fn new() -> Self {
// Const assert N > 0
crate::sealed::greater_than_0::<N>();
const {
assert!(N > 0);
}
Self {
phantom: PhantomData,

View File

@ -208,8 +208,9 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
/// ```
#[inline]
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_0::<N>();
const {
assert!(N > 0);
}
Self {
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> {
/// Creates an empty `IndexMap`.
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_1::<N>();
crate::sealed::power_of_two::<N>();
const {
assert!(N > 1);
assert!(N.is_power_of_two());
}
Self {
build_hasher: BuildHasherDefault::new(),
@ -1236,9 +1237,10 @@ where
S: Default,
{
fn default() -> Self {
// Const assert
crate::sealed::greater_than_1::<N>();
crate::sealed::power_of_two::<N>();
const {
assert!(N > 1);
assert!(N.is_power_of_two());
}
Self {
build_hasher: <_>::default(),

View File

@ -221,8 +221,6 @@ pub mod spsc;
#[cfg(feature = "ufmt")]
mod ufmt;
mod sealed;
/// Implementation details for macros.
/// Do not use. Used for macros only. Not covered by semver guarantees.
#[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>;
impl<T, const N: usize> MpMcQueue<T, N> {
const ASSERT: [(); 1] = [()];
/// Creates an empty queue
pub const fn new() -> Self {
// Const assert
crate::sealed::greater_than_1::<N>();
crate::sealed::power_of_two::<N>();
// Const assert on size.
#[allow(clippy::no_effect)]
Self::ASSERT[(N >= (UintSize::MAX as usize)) as usize];
const {
assert!(N > 1);
assert!(N.is_power_of_two());
assert!(N < UintSize::MAX as usize);
}
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.
pub const fn $new_name() -> Self {
// Const assert N < MAX
crate::sealed::smaller_than::<N, $max_val>();
const {
assert!(N < $max_val);
}
let mut list = SortedLinkedList {
list: OwnedSortedLinkedListStorage {

View File

@ -143,8 +143,9 @@ pub type QueueView<T> = QueueInner<T, ViewStorage>;
impl<T, const N: usize> Queue<T, N> {
/// Creates an empty queue with a fixed capacity of `N - 1`
pub const fn new() -> Self {
// Const assert N > 1
crate::sealed::greater_than_1::<N>();
const {
assert!(N > 1);
}
Queue {
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
/// vector a compile-time error will be produced.
pub fn from_array<const M: usize>(src: [T; M]) -> Self {
// Const assert M >= 0
crate::sealed::greater_than_eq_0::<M>();
// Const assert N >= M
crate::sealed::greater_than_eq::<N, M>();
const {
assert!(N >= M);
}
// We've got to copy `src`, but we're functionally moving it. Don't run
// any Drop code for T.