Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/access.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
//! Marker types for limiting access.

/// Private trait that is implemented for the types in this module.
pub trait Access: Copy + Default {
/// Ensures that this trait cannot be implemented outside of this crate.
#[doc(hidden)]
fn _private() -> _Private {
_Private
}

/// Sealed trait that is implemented for the types in this module.
pub trait Access: Copy + Default + private::Sealed {
/// Reduced access level to safely share the corresponding value.
type RestrictShared: Access;
}

/// Helper trait that is implemented by [`ReadWrite`] and [`ReadOnly`].
pub trait Readable: Copy + Default {
pub trait Readable: Copy + Default + private::Sealed {
/// Reduced access level to safely share the corresponding value.
type RestrictShared: Readable + Access;

/// Ensures that this trait cannot be implemented outside of this crate.
fn _private() -> _Private {
_Private
}
}

/// Helper trait that is implemented by [`ReadWrite`] and [`WriteOnly`].
pub trait Writable: Access {
/// Ensures that this trait cannot be implemented outside of this crate.
fn _private() -> _Private {
_Private
}
}
pub trait Writable: Access + private::Sealed {}

/// Implemented for access types that permit copying of `VolatileRef`.
pub trait Copyable {
/// Ensures that this trait cannot be implemented outside of this crate.
fn _private() -> _Private {
_Private
}
}
pub trait Copyable: private::Sealed {}

impl<T> Access for T
where
Expand Down Expand Up @@ -78,6 +57,11 @@ impl Access for NoAccess {
}
impl Copyable for NoAccess {}

#[non_exhaustive]
#[doc(hidden)]
pub struct _Private;
mod private {
pub trait Sealed {}

impl Sealed for super::ReadWrite {}
impl Sealed for super::ReadOnly {}
impl Sealed for super::WriteOnly {}
impl Sealed for super::NoAccess {}
}