Skip to content

Commit

Permalink
Removed dependency on spin crate and its corresponding trait implem…
Browse files Browse the repository at this point in the history
…entations.
  • Loading branch information
kevinaboos committed Jun 7, 2018
1 parent fb924d6 commit 8aa58b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ An unsafe marker trait for types like Box and Rc that dereference to a stable ad
default = ["std"]
std = []
alloc = []
spin_mutex = [ "spin" ]

[dependencies.spin]
version = "0.4.5"
optional = true
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ Enable the "alloc" feature (with default-features disabled) to have this trait b
* `alloc::arc::Arc`
* `alloc::string::String`

Enable the "spin_mutex" feature (with default-features disabled) to have this trait be implemented for the following types from the [spin](https://crates.io/crates/spin) crate:
* `spin::MutexGuard`
* `spin::RwLockReadGuard`
* `spin::RwLockWriteGuard`
For example, this crate can be built with alloc support via the following command:
`cargo build --no-default-features --features alloc`

Or added as a `Cargo.toml` dependency as follows:
```
[dependencies.stable_deref_trait]
version = "<version>"
default-features = false
features = [ "alloc" ]
```
14 changes: 4 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It is intended to be used by crates such as [owning_ref](https://crates.io/crate
no_std support can be enabled by disabling default features (specifically "std"). In this case, the trait will not be implemented for the std types mentioned above, but you can still use it for your own types.
*/

#![feature(alloc)]
#![cfg_attr(feature = "alloc", feature(alloc))]

#![cfg_attr(not(feature = "std"), no_std)]

Expand All @@ -24,9 +24,6 @@ extern crate core;
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "spin")]
extern crate spin;

use core::ops::Deref;


Expand Down Expand Up @@ -165,9 +162,6 @@ use alloc::string::String;

#[cfg(feature = "std")]
use std::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "spin")]
use spin::{MutexGuard, RwLockReadGuard, RwLockWriteGuard};


#[cfg(feature = "std")]
use std::cell::{Ref, RefMut};
Expand Down Expand Up @@ -195,11 +189,11 @@ unsafe impl<T: ?Sized> CloneStableDeref for Arc<T> {}
unsafe impl<'a, T: ?Sized> StableDeref for Ref<'a, T> {}
// #[cfg(any(feature = "std", feature = "alloc"))]
unsafe impl<'a, T: ?Sized> StableDeref for RefMut<'a, T> {}
#[cfg(any(feature = "std", feature = "spin"))]
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for MutexGuard<'a, T> {}
#[cfg(any(feature = "std", feature = "spin"))]
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for RwLockReadGuard<'a, T> {}
#[cfg(any(feature = "std", feature = "spin"))]
#[cfg(feature = "std")]
unsafe impl<'a, T: ?Sized> StableDeref for RwLockWriteGuard<'a, T> {}

unsafe impl<'a, T: ?Sized> StableDeref for &'a T {}
Expand Down

0 comments on commit 8aa58b5

Please sign in to comment.