Skip to content

Commit

Permalink
Support no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Jun 6, 2020
1 parent cb093b0 commit 13c33dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ description = """
Send-able cell type whose contents can be accessed only via an inforgeable token.
"""
keywords = ["token", "lock", "cell"]
categories = ["rust-patterns", "no-std"]

[features]
default = ["std"]
std = []

[badges]
maintenance = { status = "passively-maintained" }
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@
//! let read_guard1 = lock.read(&token).unwrap();
//! let read_guard2 = lock.read(&token).unwrap();
//! ```
use std::cell::UnsafeCell;
use std::fmt;
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
use core as std_core;
#[cfg(feature = "std")]
use std as std_core;

use self::std_core::cell::UnsafeCell;
use self::std_core::fmt;

#[cfg(feature = "std")]
mod arc;
#[cfg(feature = "std")]
mod rc;
#[cfg(feature = "std")]
pub use self::{arc::*, rc::*};

/// Trait for an unforgeable token used to access the contents of a
Expand Down Expand Up @@ -183,6 +193,7 @@ impl<T: ?Sized, I> TokenLock<T, I> {
}

#[test]
#[cfg(feature = "std")]
fn basic() {
let mut token = ArcToken::new();
let lock = TokenLock::new(token.id(), 1);
Expand All @@ -193,6 +204,7 @@ fn basic() {
}

#[test]
#[cfg(feature = "std")]
fn bad_token() {
let token1 = ArcToken::new();
let mut token2 = ArcToken::new();
Expand Down

0 comments on commit 13c33dd

Please sign in to comment.