From 685d4ebe45627caf1b9072f93ab894500a72a224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 25 Apr 2024 16:53:57 +0200 Subject: [PATCH] fix(access): properly seal access traits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/access.rs | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/access.rs b/src/access.rs index 42d4ec6..6d529bd 100644 --- a/src/access.rs +++ b/src/access.rs @@ -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 Access for T where @@ -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 {} +}