Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch optional core feature to default std feature #168

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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