seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
585 stars 114 forks source link

Add no_std feature, impl std::error::Error #22

Closed abonander closed 7 years ago

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.3%) to 97.033% when pulling 16da533a949afb877ac74e74b0a21b07ead8d833 on abonander:master into 49bf4d81d44dbc736ad48438540bebc5f6d17e22 on seanmonstar:master.

abonander commented 7 years ago

@seanmonstar Are you waiting to publish a new version or did you forget again? ;P

seanmonstar commented 7 years ago

Something tickles me weird about having the no_std be a feature. I wanted to think about it some to see if there's something better.

abonander commented 7 years ago

It's a common convention, I made it a default so it didn't break any existing usage expecting it to work with core right out of the box.

abonander commented 7 years ago

@seanmonstar Would you prefer to leave the #![no_std] unconditional and just have a std feature? I think that would work:

#![no_std] 

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
impl ::std::error::Error for Error { /* ... */ }
seanmonstar commented 7 years ago

Ignore me, it's perfect. Thanks!

jethrogb commented 7 years ago

The convention is to have a feature named std, see this comment for rationale.

Using this convention is not a breaking change, since no httparse versions that use no_std have been published yet.

seanmonstar commented 7 years ago

@jethrogb so, have this instead:

[features]
default = ["std"]
std = []

And anyone wanting to use it in a no_std environment sets default-features = false.

seanmonstar commented 7 years ago

If that seems correct, I've made a PR to do that, and I can release the new version today https://github.com/seanmonstar/httparse/pull/23