Skip to content

Commit c8d34b6

Browse files
committed
Move LenType implementation to Sealed
1 parent a16a927 commit c8d34b6

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

src/len_type.rs

+21-28
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,8 @@ use core::{
33
ops::{Add, AddAssign, Sub, SubAssign},
44
};
55

6-
mod private {
7-
pub trait Sealed {}
8-
9-
impl Sealed for u8 {}
10-
impl Sealed for u16 {}
11-
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
12-
impl Sealed for u32 {}
13-
14-
impl Sealed for usize {}
15-
}
16-
17-
macro_rules! impl_lentype {
18-
($($(#[$meta:meta])* $LenT:ty),*) => {$(
19-
$(#[$meta])*
20-
impl LenType for $LenT {
21-
const ZERO: Self = 0;
22-
const ONE: Self = 1;
23-
const MAX: usize = Self::MAX as _;
24-
}
25-
)*}
26-
}
27-
28-
/// A sealed trait representing a valid type to use as a length for a container.
29-
///
30-
/// This cannot be implemented in user code, and is restricted to `u8`, `u16`, `u32`, and `usize`.
31-
pub trait LenType:
32-
private::Sealed
33-
+ Send
6+
pub trait Sealed:
7+
Send
348
+ Sync
359
+ Copy
3610
+ Display
@@ -62,6 +36,25 @@ pub trait LenType:
6236
}
6337
}
6438

39+
macro_rules! impl_lentype {
40+
($($(#[$meta:meta])* $LenT:ty),*) => {$(
41+
$(#[$meta])*
42+
impl Sealed for $LenT {
43+
const ZERO: Self = 0;
44+
const ONE: Self = 1;
45+
const MAX: usize = Self::MAX as _;
46+
}
47+
48+
$(#[$meta])*
49+
impl LenType for $LenT {}
50+
)*}
51+
}
52+
53+
/// A sealed trait representing a valid type to use as a length for a container.
54+
///
55+
/// This cannot be implemented in user code, and is restricted to `u8`, `u16`, `u32`, and `usize`.
56+
pub trait LenType: Sealed {}
57+
6558
impl_lentype!(
6659
u8,
6760
u16,

src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<T, LenT: LenType, const N: usize> Vec<T, N, LenT> {
348348
if N == M {
349349
Self {
350350
phantom: PhantomData,
351-
len: LenType::from_usize(N),
351+
len: LenT::from_usize(N),
352352
// NOTE(unsafe) ManuallyDrop<[T; M]> and [MaybeUninit<T>; N]
353353
// have the same layout when N == M.
354354
buffer: unsafe { mem::transmute_copy(&src) },

0 commit comments

Comments
 (0)