From 645e23dda30ac1b99af39f201a74211e7ac3251a Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Thu, 18 Jul 2019 11:59:52 -0700 Subject: [PATCH] switch optional `core` feature to default `std` feature --- .circleci/config.yml | 4 ++-- README.md | 10 ++++++++-- phf/Cargo.toml | 3 ++- phf/src/lib.rs | 8 ++++---- phf_shared/Cargo.toml | 3 ++- phf_shared/src/lib.rs | 8 ++++---- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4bccb88b..0ab56368 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: @@ -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 diff --git a/README.md b/README.md index 947843dc..d0fefc20 100644 --- a/README.md +++ b/README.md @@ -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 =========== diff --git a/phf/Cargo.toml b/phf/Cargo.toml index 824719cc..84ce9b3f 100644 --- a/phf/Cargo.toml +++ b/phf/Cargo.toml @@ -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", diff --git a/phf/src/lib.rs b/phf/src/lib.rs index c6d2dd2d..8f22ab91 100644 --- a/phf/src/lib.rs +++ b/phf/src/lib.rs @@ -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")] @@ -128,7 +128,7 @@ pub mod ordered_set; #[doc(hidden)] pub enum Slice { Static(&'static [T]), - #[cfg(not(feature = "core"))] + #[cfg(feature = "std")] Dynamic(Vec), } @@ -138,7 +138,7 @@ impl Deref for Slice { fn deref(&self) -> &[T] { match *self { Slice::Static(t) => t, - #[cfg(not(feature = "core"))] + #[cfg(feature = "std")] Slice::Dynamic(ref t) => t, } } diff --git a/phf_shared/Cargo.toml b/phf_shared/Cargo.toml index 83baecad..05344ebc 100644 --- a/phf_shared/Cargo.toml +++ b/phf_shared/Cargo.toml @@ -13,7 +13,8 @@ path = "src/lib.rs" test = false [features] -core = [] +default = ["std"] +std = [] [dependencies] siphasher = "0.3" diff --git a/phf_shared/src/lib.rs b/phf_shared/src/lib.rs index 4ce8bdf0..7e1efdcb 100644 --- a/phf_shared/src/lib.rs +++ b/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; @@ -111,7 +111,7 @@ delegate_debug!(u128); delegate_debug!(i128); delegate_debug!(bool); -#[cfg(not(feature = "core"))] +#[cfg(feature = "std")] impl PhfHash for String { #[inline] fn phf_hash(&self, state: &mut H) { @@ -119,7 +119,7 @@ impl PhfHash for String { } } -#[cfg(not(feature = "core"))] +#[cfg(feature = "std")] impl PhfHash for Vec { #[inline] fn phf_hash(&self, state: &mut H) {