|
1 | 1 | //! Marker types for limiting access.
|
2 | 2 |
|
3 |
| -/// Private trait that is implemented for the types in this module. |
4 |
| -pub trait Access: Copy + Default { |
5 |
| - /// Ensures that this trait cannot be implemented outside of this crate. |
6 |
| - #[doc(hidden)] |
7 |
| - fn _private() -> _Private { |
8 |
| - _Private |
9 |
| - } |
10 |
| - |
| 3 | +/// Sealed trait that is implemented for the types in this module. |
| 4 | +pub trait Access: Copy + Default + private::Sealed { |
11 | 5 | /// Reduced access level to safely share the corresponding value.
|
12 | 6 | type RestrictShared: Access;
|
13 | 7 | }
|
14 | 8 |
|
15 | 9 | /// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
|
16 |
| -pub trait Readable: Copy + Default { |
| 10 | +pub trait Readable: Copy + Default + private::Sealed { |
17 | 11 | /// Reduced access level to safely share the corresponding value.
|
18 | 12 | type RestrictShared: Readable + Access;
|
19 |
| - |
20 |
| - /// Ensures that this trait cannot be implemented outside of this crate. |
21 |
| - fn _private() -> _Private { |
22 |
| - _Private |
23 |
| - } |
24 | 13 | }
|
25 | 14 |
|
26 | 15 | /// Helper trait that is implemented by [`ReadWrite`] and [`WriteOnly`].
|
27 |
| -pub trait Writable: Access { |
28 |
| - /// Ensures that this trait cannot be implemented outside of this crate. |
29 |
| - fn _private() -> _Private { |
30 |
| - _Private |
31 |
| - } |
32 |
| -} |
| 16 | +pub trait Writable: Access + private::Sealed {} |
33 | 17 |
|
34 | 18 | /// Implemented for access types that permit copying of `VolatileRef`.
|
35 |
| -pub trait Copyable { |
36 |
| - /// Ensures that this trait cannot be implemented outside of this crate. |
37 |
| - fn _private() -> _Private { |
38 |
| - _Private |
39 |
| - } |
40 |
| -} |
| 19 | +pub trait Copyable: private::Sealed {} |
41 | 20 |
|
42 | 21 | impl<T> Access for T
|
43 | 22 | where
|
@@ -78,6 +57,11 @@ impl Access for NoAccess {
|
78 | 57 | }
|
79 | 58 | impl Copyable for NoAccess {}
|
80 | 59 |
|
81 |
| -#[non_exhaustive] |
82 |
| -#[doc(hidden)] |
83 |
| -pub struct _Private; |
| 60 | +mod private { |
| 61 | + pub trait Sealed {} |
| 62 | + |
| 63 | + impl Sealed for super::ReadWrite {} |
| 64 | + impl Sealed for super::ReadOnly {} |
| 65 | + impl Sealed for super::WriteOnly {} |
| 66 | + impl Sealed for super::NoAccess {} |
| 67 | +} |
0 commit comments