Skip to content

Commit

Permalink
epoch: Seal Pointer trait
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 23, 2022
1 parent 568f558 commit 1d22218
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crossbeam-epoch/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,9 @@ impl<T> From<*const T> for Atomic<T> {
}

/// A trait for either `Owned` or `Shared` pointers.
// TODO: seal this trait https://github.com/crossbeam-rs/crossbeam/issues/620
pub trait Pointer<T: ?Sized + Pointable> {
///
/// This trait is sealed and cannot be implemented for types outside of `crossbeam-epoch`.
pub trait Pointer<T: ?Sized + Pointable>: crate::sealed::Sealed {
/// Returns the machine representation of the pointer.
fn into_ptr(self) -> *mut ();

Expand All @@ -916,6 +917,7 @@ pub struct Owned<T: ?Sized + Pointable> {
_marker: PhantomData<Box<T>>,
}

impl<T: ?Sized + Pointable> crate::sealed::Sealed for Owned<T> {}
impl<T: ?Sized + Pointable> Pointer<T> for Owned<T> {
#[inline]
fn into_ptr(self) -> *mut () {
Expand Down Expand Up @@ -1176,6 +1178,7 @@ impl<T: ?Sized + Pointable> Clone for Shared<'_, T> {

impl<T: ?Sized + Pointable> Copy for Shared<'_, T> {}

impl<T: ?Sized + Pointable> crate::sealed::Sealed for Shared<'_, T> {}
impl<T: ?Sized + Pointable> Pointer<T> for Shared<'_, T> {
#[inline]
fn into_ptr(self) -> *mut () {
Expand Down
4 changes: 4 additions & 0 deletions crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ cfg_if! {
};
pub use self::collector::{Collector, LocalHandle};
pub use self::guard::{unprotected, Guard};

mod sealed {
pub trait Sealed {}
}
}
}

Expand Down

0 comments on commit 1d22218

Please sign in to comment.