Skip to content

Commit ae808c9

Browse files
committed
seal the Uxx trait
1 parent ddc6842 commit ae808c9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/ring_buffer/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod spsc;
1919
/// Types that can be used as `RingBuffer` indices: `u8`, `u16` and `usize
2020
///
2121
/// This trait is sealed and cannot be implemented outside of `heapless`.
22-
pub unsafe trait Uxx: Into<usize> + Send {
22+
pub unsafe trait Uxx: Into<usize> + Send + private::Sealed {
2323
#[doc(hidden)]
2424
fn truncate(x: usize) -> Self;
2525

@@ -54,6 +54,16 @@ pub unsafe trait Uxx: Into<usize> + Send {
5454
fn store_release(x: *mut Self, val: Self);
5555
}
5656

57+
mod private {
58+
pub trait Sealed {}
59+
60+
impl Sealed for usize {}
61+
#[cfg(feature = "smaller-atomics")]
62+
impl Sealed for u8 {}
63+
#[cfg(feature = "smaller-atomics")]
64+
impl Sealed for u16 {}
65+
}
66+
5767
#[cfg(feature = "smaller-atomics")]
5868
unsafe impl Uxx for u8 {
5969
fn truncate(x: usize) -> Self {

0 commit comments

Comments
 (0)