Navigation Menu

Skip to content

Commit

Permalink
switch optional core feature to default std feature
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Jul 18, 2019
1 parent 50c6c75 commit 645e23d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -35,7 +35,7 @@ jobs:
- run: cargo test
- run: (cd phf_macros && cargo test)
- run: cargo test -p phf_codegen_test
- run: (cd phf_shared && cargo build --features core)
- run: (cd phf && cargo build --no-default-features)
- *SAVE_DEPS
nightly:
docker:
Expand All @@ -51,7 +51,7 @@ jobs:
- run: cargo test
- run: (cd phf_macros && cargo test && cargo test -- --ignored --test-threads=1)
- run: cargo test -p phf_codegen_test
- run: (cd phf_shared && cargo build --features core)
- run: (cd phf && cargo build --no-default-features)

workflows:
version: 2
Expand Down
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -23,9 +23,15 @@ PHF data structures can be constucted via either the procedural
macros in the `phf_macros` crate or code generation supported by the
`phf_codegen` crate.

The `phf/core` feature will compile the `phf` crate with a dependency on
To compile the `phf` crate with a dependency on
libcore instead of libstd, enabling use in environments where libstd
will not work.
will not work, set `default-features = false` for the dependency:

```toml
[dependencies]
# to use `phf` in `no_std` environments
phf = { version = "0.8", default-features = false }
```

phf_macros
===========
Expand Down
3 changes: 2 additions & 1 deletion phf/Cargo.toml
Expand Up @@ -13,7 +13,8 @@ path = "src/lib.rs"
test = false

[features]
core = ["phf_shared/core"]
default = ["std"]
std = ["phf_shared/std"]
unicase = ["phf_shared/unicase"]
macros = [
"phf_macros",
Expand Down
8 changes: 4 additions & 4 deletions phf/src/lib.rs
Expand Up @@ -38,9 +38,9 @@
//! in a build script)
#![doc(html_root_url="https://docs.rs/phf/0.7")]
#![warn(missing_docs)]
#![cfg_attr(feature = "core", no_std)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
extern crate std as core;

#[cfg(feature = "macros")]
Expand Down Expand Up @@ -128,7 +128,7 @@ pub mod ordered_set;
#[doc(hidden)]
pub enum Slice<T: 'static> {
Static(&'static [T]),
#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
Dynamic(Vec<T>),
}

Expand All @@ -138,7 +138,7 @@ impl<T> Deref for Slice<T> {
fn deref(&self) -> &[T] {
match *self {
Slice::Static(t) => t,
#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
Slice::Dynamic(ref t) => t,
}
}
Expand Down
3 changes: 2 additions & 1 deletion phf_shared/Cargo.toml
Expand Up @@ -13,7 +13,8 @@ path = "src/lib.rs"
test = false

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

[dependencies]
siphasher = "0.3"
Expand Down
8 changes: 4 additions & 4 deletions phf_shared/src/lib.rs
@@ -1,7 +1,7 @@
#![doc(html_root_url = "https://docs.rs/phf_shared/0.7")]
#![cfg_attr(feature = "core", no_std)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
extern crate std as core;

extern crate siphasher;
Expand Down Expand Up @@ -111,15 +111,15 @@ delegate_debug!(u128);
delegate_debug!(i128);
delegate_debug!(bool);

#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
impl PhfHash for String {
#[inline]
fn phf_hash<H: Hasher>(&self, state: &mut H) {
(**self).phf_hash(state)
}
}

#[cfg(not(feature = "core"))]
#[cfg(feature = "std")]
impl PhfHash for Vec<u8> {
#[inline]
fn phf_hash<H: Hasher>(&self, state: &mut H) {
Expand Down

0 comments on commit 645e23d

Please sign in to comment.