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

Simplify cfgs and allow testing without default features. #253

Merged
merged 2 commits into from
Sep 24, 2023

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Sep 16, 2023

This PR contains two commits which address different matters, but the second depends on and helps test the first. If desired, I can split it into two PRs, or discard either one and keep the other.


First: no_std import simplification.

It's always OK to use core and alloc if you're using std, and core if you're using alloc. Therefore, code can be simplified by using alloc even if std is also being used, and so on.

  • Make std feature depend on alloc feature.
  • Simplify cfg()s by making that assumption.
  • Don't import std aliased as alloc; use alloc directly.

These changes do not affect the public API of the crate in any way, but should make maintenance slightly easier since there are fewer subtly-different conditions under which the code might be compiled.


Second: Allow cargo test to complete under any set of features.

Previously, tests, examples, and benches would fail to compile under cargo test --no-default-features. Now they are all skipped if they would not compile.

This does not affect behavior with default features — test coverage is not reduced.

It's always OK to use `core` and `alloc` if you're using `std`, and
`core` if you're using `alloc`. Therefore, code can be simplified by
using `alloc` even if `std` is also being used, and so on.

* Make `std` feature depend on `alloc` feature.
* Simplify `cfg()`s by making that assumption.
* Don't import `std` aliased as `alloc`; use `alloc` directly.

These changes do not affect the public API of the crate in any way.
Previously, tests, examples, and benches would fail to compile under
`cargo test --no-default-features`. Now they are all skipped if they
would not compile.

This does not affect behavior *with* default features — test coverage
is not reduced.
@marshallpierce
Copy link
Owner

Thanks for the cleanup!

@marshallpierce marshallpierce merged commit 9eaf503 into marshallpierce:master Sep 24, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants