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

Fix that std was Still Required Through lazy_static #15

Merged
merged 1 commit into from
Apr 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,24 @@ required-features = ["alloc"]

[features]
default = ["alloc"] # default features are automatically enables (if not opt-out)
alloc = ["hashbrown"] # requires global allocator, enables various functions such as parse_alias
alloc = [ # requires global allocator, enables various functions such as parse_alias
"hashbrown",
"lazy_static"
]
doc_cfg = [] # requires nightly compiler, only intended for docs.rs builds (enables usage of doc_cfg)

[dependencies]
lazy_static = "1.4.0"

[dependencies.lazy_static]
version = "1.4.0"
optional = true
# The following feature on `lazy_static` would remove the transitive dependency of lazy_static on
# std, which is necessary if targetting a platform without it. However, since the current version
# of Cargo (1.51.0) unifies features acros crates, requiring that feature here, would make
# lazy_static globally use spinloks instead of mutices. So, it seems more reasonable that a final
# user (binary crate) adds this feature if they want `alloc` but not `std`.
# Also see: https://github.com/rust-lang-nursery/lazy-static.rs/issues/150
#features = ["spin_no_std"] # Would remove std from lazy_static, but it has side-effects

[dependencies.hashbrown]
version = "0.11"
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,32 @@ platforms. However, some functions such as [`parse_alias`](https://docs.rs/emoji
ad-hoc flag functions need the `alloc` crate (normally part of `std`),
thus it is enabled by default.

- `default`: (implies `alloc`) automatically enabled if not opt-out:
- `default`: (implies `alloc`) \
Automatically enabled if not opt-out:
```toml
[dependencies.emojic]
version = "0.3"
default-features = false
```
- `alloc`: requires a global allocator, enables various functions such as `parse_alias` as well
as the ad-hoc flag functions (the flag constants are unaffected)
- `alloc`: (implies `hashbrown` and `lazy_static`) \
Requires a global allocator,
enables various functions such as `parse_alias` as well
as the ad-hoc flag functions (the flag constants are unaffected).

Notice, that `lazy_static`, by default, pulls-in `std` to use mutices for waiting.
This is good if you do have `std` available, and bad if not. However, the alternative is
to instruct `lazy_static` to use spinlocks instead. Yet, since crate-features are unified by
Cargo, it would be bad for all user that have `std`, to requiring it by default.
Instead, if you want to use this `alloc` feature, but you don't have `std`
(e.g. in your binary crate), you can simply add `lazy_static` yourself, and make it to use
spinlocks, which will apply globally. E.g. add to your `Cargo.toml`:
```toml
[dependencies.lazy_static]
version = "1.4"
features = ["spin_no_std"]
```
Also see: <https://github.com/rust-lang-nursery/lazy-static.rs/issues/150>




Expand Down
24 changes: 21 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,32 @@
//! ad-hoc flag functions need the `alloc` crate (normally part of `std`),
//! thus it is enabled by default.
//!
//! - `default`: (implies `alloc`) automatically enabled if not opt-out:
//! - `default`: (implies `alloc`) \
//! Automatically enabled if not opt-out:
//! ```toml
//! [dependencies.emojic]
//! version = "0.3"
//! default-features = false
//! ```
//! - `alloc`: requires a global allocator, enables various functions such as `parse_alias` as well
//! as the ad-hoc flag functions (the flag constants are unaffected)
//! - `alloc`: (implies `hashbrown` and `lazy_static`) \
//! Requires a global allocator,
//! enables various functions such as `parse_alias` as well
//! as the ad-hoc flag functions (the flag constants are unaffected).
//!
//! Notice, that `lazy_static`, by default, pulls-in `std` to use mutices for waiting.
//! This is good if you do have `std` available, and bad if not. However, the alternative is
//! to instruct `lazy_static` to use spinlocks instead. Yet, since crate-features are unified by
//! Cargo, it would be bad for all user that have `std`, to requiring it by default.
//! Instead, if you want to use this `alloc` feature, but you don't have `std`
//! (e.g. in your binary crate), you can simply add `lazy_static` yourself, and make it to use
//! spinlocks, which will apply globally. E.g. add to your `Cargo.toml`:
//! ```toml
//! [dependencies.lazy_static]
//! version = "1.4"
//! features = ["spin_no_std"]
//! ```
//! Also see: <https://github.com/rust-lang-nursery/lazy-static.rs/issues/150>
//!
//!
//!

Expand Down