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

Support no_std #14

Merged
merged 4 commits into from
Mar 18, 2018
Merged

Support no_std #14

merged 4 commits into from
Mar 18, 2018

Conversation

glandium
Copy link
Contributor

Fixes #3.

Copy link
Owner

@dtolnay dtolnay left a 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?

@glandium
Copy link
Contributor Author

It's rather unconventional to support both std::fmt::Write and std::io::Write at the same time. How would you go about it?

@glandium
Copy link
Contributor Author

Oh, I see issue #5.

Copy link
Owner

@dtolnay dtolnay left a 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 = []
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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>;
Copy link
Owner

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.

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit c1c4f73 into dtolnay:master Mar 18, 2018
@dtolnay
Copy link
Owner

dtolnay commented Mar 18, 2018

I released 0.4.0 with this change.

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.

2 participants