Skip to content

Commit

Permalink
no_std support
Browse files Browse the repository at this point in the history
Changes references from std:: to core:: where applicable, ensuring the crate
builds in no_std environments.
  • Loading branch information
tarcieri committed Aug 5, 2017
1 parent 029223c commit dd2e32c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ matrix:
env: FEATURES=--features=nightly
- rust: beta
env: FEATURES=--features=nightly
include:
- rust: beta
script: cargo build --verbose --no-default-features --features=no_cc
script: cargo build --verbose --no-default-features --features=nightly
script: cargo build --verbose --release --no-default-features --features=no_cc
script: cargo build --verbose --release --no-default-features --features=nightly
script:
- cargo build --verbose $FEATURES
- cargo test --verbose $FEATURES
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ license = "MIT OR Apache-2.0"
build = "build.rs"

[features]
default = ["std"]
no_cc = []
nightly = ["no_cc"]
std = []

[build-dependencies]
gcc = "0.3"

[dependencies]
4 changes: 2 additions & 2 deletions src/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
//! assert!(!as_bytes(&place).contains(&0x41));
//! ```
use std::mem;
use std::ptr;
use core::mem;
use core::ptr;

use hide::hide_mem_impl;

Expand Down
22 changes: 11 additions & 11 deletions src/clear_on_drop.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::borrow::{Borrow, BorrowMut};
use std::cmp::Ordering;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
use core::borrow::{Borrow, BorrowMut};
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::mem;
use core::ops::{Deref, DerefMut};
use core::ptr;

use clear::Clear;

Expand Down Expand Up @@ -138,7 +138,7 @@ impl<P> Drop for ClearOnDrop<P>
}
}

// std::convert traits
// core::convert traits

impl<P, T: ?Sized> AsRef<T> for ClearOnDrop<P>
where P: DerefMut + AsRef<T>,
Expand All @@ -160,7 +160,7 @@ impl<P, T: ?Sized> AsMut<T> for ClearOnDrop<P>
}
}

// std::borrow traits
// core::borrow traits

// The `T: Clear` bound avoids a conflict with the blanket impls
// `impl<T> Borrow<T> for T` and `impl<T> BorrowMut<T> for T`, since
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<P, T: ?Sized> BorrowMut<T> for ClearOnDrop<P>
}
}

// std::hash traits
// core::hash traits

impl<P> Hash for ClearOnDrop<P>
where P: DerefMut + Hash,
Expand All @@ -200,7 +200,7 @@ impl<P> Hash for ClearOnDrop<P>
}
}

// std::cmp traits
// core::cmp traits

impl<P, Q> PartialEq<ClearOnDrop<Q>> for ClearOnDrop<P>
where P: DerefMut + PartialEq<Q>,
Expand Down
6 changes: 3 additions & 3 deletions src/hide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn hide_ptr<P>(mut ptr: P) -> P {
#[cfg(feature = "nightly")]
pub use self::nightly::*;

#[cfg(not(feature = "no_cc"))]
#[cfg(all(not(feature = "no_cc"), feature = "std"))]
pub use self::cc::*;

#[cfg(all(feature = "no_cc", not(feature = "nightly")))]
Expand Down Expand Up @@ -63,7 +63,7 @@ mod nightly {
}

// When a C compiler is available, a dummy C function can be used.
#[cfg(not(feature = "no_cc"))]
#[cfg(all(not(feature = "no_cc"), feature = "std"))]
mod cc {
use std::os::raw::c_void;

Expand All @@ -83,7 +83,7 @@ mod cc {
// and hope this is enough to confuse the optimizer.
#[cfg(all(feature = "no_cc", not(feature = "nightly")))]
mod fallback {
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
use core::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};

#[inline]
pub fn hide_mem_impl<T: ?Sized>(ptr: *mut T) {
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(asm))]
#![cfg_attr(feature = "nightly", feature(i128_type))]
#![cfg_attr(feature = "nightly", feature(specialization))]
Expand Down Expand Up @@ -55,6 +56,9 @@
//! the `no_cc` feature, works on stable Rust, and does not need a C
//! compiler.
#[cfg(feature = "std")]
extern crate core;

pub mod clear;
mod clear_on_drop;
mod clear_stack_on_return;
Expand Down

0 comments on commit dd2e32c

Please sign in to comment.