Skip to content

Commit

Permalink
Merge pull request #7 from artichoke/send-sync
Browse files Browse the repository at this point in the history
Remove explicit negative Send and Sync impls
  • Loading branch information
lopopolo committed Jul 23, 2019
2 parents 5cd68de + bcd66c0 commit d9388fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
alloc_layout_extra,
box_into_raw_non_null,
dropck_eyepatch,
optin_builtin_traits,
specialization
)]
#![deny(warnings, intra_doc_link_resolution_failure, missing_docs)]
Expand Down Expand Up @@ -42,6 +41,8 @@
//! If you do not depend on these APIs, `cactusref` is a drop-in replacement for
//! [`std::rc`].
//!
//! Like [`std::rc`], [`Rc`] and [`Weak`] are `!`[`Send`] and `!`[`Sync`].
//!
//! ## Cycle Detection
//!
//! `Rc` implements [`Adoptable`] to log bookkeeping entries for strong
Expand Down
17 changes: 14 additions & 3 deletions src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ use crate::Weak;
/// that you have to call them as e.g., [`Rc::get_mut(&mut value)`](Rc::get_mut)
/// instead of `value.get_mut()`. This avoids conflicts with methods of the
/// inner type `T`.
///
/// Like [`std::rc::Rc`], `Rc` is `!`[`Send`] and `!`[`Sync`].
///
/// ```rust,compile_fail
/// # use cactusref::Rc;
/// fn requires_send<T: Send>(s: T) {}
/// requires_send(Rc::new(5));
/// ```
///
/// ```rust,compile_fail
/// # use cactusref::Rc;
/// fn requires_sync<T: Sync>(s: T) {}
/// requires_sync(Rc::new(5));
/// ```
pub struct Rc<T: ?Sized> {
pub(crate) ptr: NonNull<RcBox<T>>,
pub(crate) phantom: PhantomData<T>,
}

impl<T: ?Sized> !Send for Rc<T> {}
impl<T: ?Sized> !Sync for Rc<T> {}

impl<T> Rc<T> {
/// Constructs a new `Rc<T>`.
///
Expand Down
19 changes: 16 additions & 3 deletions src/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ use crate::Rc;
/// pointers from children back to their parents.
///
/// The typical way to obtain a `Weak` pointer is to call [`Rc::downgrade`].
///
/// Like [`std::rc::Weak`], `Weak` is `!`[`Send`] and `!`[`Sync`].
///
/// ```rust,compile_fail
/// # use cactusref::Rc;
/// fn requires_send<T: Send>(s: T) {}
/// let item = Rc::new(5);
/// requires_send(Rc::downgrade(&item));
/// ```
///
/// ```rust,compile_fail
/// # use cactusref::Rc;
/// fn requires_sync<T: Sync>(s: T) {}
/// let item = Rc::new(5);
/// requires_sync(Rc::downgrade(&item));
/// ```
pub struct Weak<T: ?Sized> {
// This is a `NonNull` to allow optimizing the size of this type in enums,
// but it is not necessarily a valid pointer.
Expand All @@ -33,9 +49,6 @@ pub struct Weak<T: ?Sized> {
pub(crate) ptr: NonNull<RcBox<T>>,
}

impl<T: ?Sized> !Send for Weak<T> {}
impl<T: ?Sized> !Sync for Weak<T> {}

impl<T> Weak<T> {
/// Constructs a new `Weak<T>`, without allocating any memory.
///
Expand Down

0 comments on commit d9388fa

Please sign in to comment.