-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Support no_std #14
Support no_std #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cargo features are required to be additive, i.e. any code that compiles without the feature must also compile with the feature. Could you come up with a different way to implement this?
It's rather unconventional to support both std::fmt::Write and std::io::Write at the same time. How would you go about it? |
Oh, I see issue #5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks promising.
Cargo.toml
Outdated
i128 = [] | ||
use_std = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out C-FEATURE for recommendations on how to name Cargo features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I mimicked the libc crate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sadly libc got this wrong, rust-lang/libc#657. It will be fixed in their next release.
src/lib.rs
Outdated
pub trait Integer { | ||
#[cfg(feature = "use_std")] | ||
fn write<W: io::Write>(self, W) -> io::Result<usize>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is still problematic.
Cargo features are required to be additive, i.e. any code that compiles without the feature must also compile with the feature.
In this case if someone downstream writes a type:
struct u24(/* ... */);
impl Integer for u24 {
fn fmt<W: fmt::Write>(self, W) -> fmt::Result {
/* ... */
}
}
their code would compile fine when our std feature is not enabled but would break when some unrelated crate depends on our std feature. That makes the feature not additive.
See C-SEALED for a pattern that would work here.
Fixes dtolnay#3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I released 0.4.0 with this change. |
Fixes #3.