Skip to content

Commit f012580

Browse files
committed
no_std support (closes #11)
Changes references from std:: to core:: where applicable, ensuring the crate builds in no_std environments.
1 parent 029223c commit f012580

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ matrix:
1313
env: FEATURES=--features=nightly
1414
- rust: beta
1515
env: FEATURES=--features=nightly
16+
include:
17+
- rust: beta
18+
env:
19+
- FEATURES=--no-default-features --features=no_cc
20+
script:
21+
- cargo build --verbose $FEATURES
22+
- cargo build --verbose --release $FEATURES
23+
- rust: nightly
24+
env:
25+
- FEATURES=--no-default-features --features=nightly
26+
script:
27+
- cargo build --verbose $FEATURES
28+
- cargo build --verbose --release $FEATURES
1629
script:
1730
- cargo build --verbose $FEATURES
1831
- cargo test --verbose $FEATURES

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ license = "MIT OR Apache-2.0"
1212
build = "build.rs"
1313

1414
[features]
15+
default = ["std"]
1516
no_cc = []
1617
nightly = ["no_cc"]
18+
std = []
1719

1820
[build-dependencies]
1921
gcc = "0.3"
20-
21-
[dependencies]

src/clear.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
//! assert!(!as_bytes(&place).contains(&0x41));
4040
//! ```
4141
42-
use std::mem;
43-
use std::ptr;
42+
use core::mem;
43+
use core::ptr;
4444

4545
use hide::hide_mem_impl;
4646

src/clear_on_drop.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::borrow::{Borrow, BorrowMut};
2-
use std::cmp::Ordering;
3-
use std::fmt;
4-
use std::hash::{Hash, Hasher};
5-
use std::mem;
6-
use std::ops::{Deref, DerefMut};
7-
use std::ptr;
1+
use core::borrow::{Borrow, BorrowMut};
2+
use core::cmp::Ordering;
3+
use core::fmt;
4+
use core::hash::{Hash, Hasher};
5+
use core::mem;
6+
use core::ops::{Deref, DerefMut};
7+
use core::ptr;
88

99
use clear::Clear;
1010

@@ -138,7 +138,7 @@ impl<P> Drop for ClearOnDrop<P>
138138
}
139139
}
140140

141-
// std::convert traits
141+
// core::convert traits
142142

143143
impl<P, T: ?Sized> AsRef<T> for ClearOnDrop<P>
144144
where P: DerefMut + AsRef<T>,
@@ -160,7 +160,7 @@ impl<P, T: ?Sized> AsMut<T> for ClearOnDrop<P>
160160
}
161161
}
162162

163-
// std::borrow traits
163+
// core::borrow traits
164164

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

191-
// std::hash traits
191+
// core::hash traits
192192

193193
impl<P> Hash for ClearOnDrop<P>
194194
where P: DerefMut + Hash,
@@ -200,7 +200,7 @@ impl<P> Hash for ClearOnDrop<P>
200200
}
201201
}
202202

203-
// std::cmp traits
203+
// core::cmp traits
204204

205205
impl<P, Q> PartialEq<ClearOnDrop<Q>> for ClearOnDrop<P>
206206
where P: DerefMut + PartialEq<Q>,

src/hide.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn hide_ptr<P>(mut ptr: P) -> P {
2525
#[cfg(feature = "nightly")]
2626
pub use self::nightly::*;
2727

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

3131
#[cfg(all(feature = "no_cc", not(feature = "nightly")))]
@@ -63,7 +63,7 @@ mod nightly {
6363
}
6464

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

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

8888
#[inline]
8989
pub fn hide_mem_impl<T: ?Sized>(ptr: *mut T) {

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
12
#![cfg_attr(feature = "nightly", feature(asm))]
23
#![cfg_attr(feature = "nightly", feature(i128_type))]
34
#![cfg_attr(feature = "nightly", feature(specialization))]
@@ -55,6 +56,9 @@
5556
//! the `no_cc` feature, works on stable Rust, and does not need a C
5657
//! compiler.
5758
59+
#[cfg(feature = "std")]
60+
extern crate core;
61+
5862
pub mod clear;
5963
mod clear_on_drop;
6064
mod clear_stack_on_return;

0 commit comments

Comments
 (0)