Skip to content

Commit e683a4f

Browse files
authored
Merge pull request #59 from mkroening/sealed
fix(access): properly seal access traits
2 parents 846c5c5 + 685d4eb commit e683a4f

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

src/access.rs

+13-29
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,22 @@
11
//! Marker types for limiting access.
22
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 {
115
/// Reduced access level to safely share the corresponding value.
126
type RestrictShared: Access;
137
}
148

159
/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
16-
pub trait Readable: Copy + Default {
10+
pub trait Readable: Copy + Default + private::Sealed {
1711
/// Reduced access level to safely share the corresponding value.
1812
type RestrictShared: Readable + Access;
19-
20-
/// Ensures that this trait cannot be implemented outside of this crate.
21-
fn _private() -> _Private {
22-
_Private
23-
}
2413
}
2514

2615
/// 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 {}
3317

3418
/// 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 {}
4120

4221
impl<T> Access for T
4322
where
@@ -78,6 +57,11 @@ impl Access for NoAccess {
7857
}
7958
impl Copyable for NoAccess {}
8059

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

Comments
 (0)