add std feature
This commit is contained in:
parent
59bc0bfd26
commit
823916346f
|
@ -31,13 +31,22 @@ before_test:
|
|||
- C:\msys64\usr\bin\bash -c "if [ -d ""$USERPROFILE/.cargo/registry/cache"" ]; then cd ""$USERPROFILE/.cargo/registry""; /c/msys64/usr/bin/find cache -name \*.crate; fi"
|
||||
|
||||
test_script:
|
||||
- cargo +beta-%TARGET% clippy --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-%TARGET% clippy --all-targets --features "fail-on-warnings az f16 serde std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az f16 std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az f16"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az serde std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az serde"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings f16 serde std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings f16 std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings f16"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings serde std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings serde"
|
||||
- cargo +beta-%TARGET% check --all-targets --features "fail-on-warnings std"
|
||||
- cargo +beta-%TARGET% check --all-targets --features fail-on-warnings
|
||||
- cargo +beta-%TARGET% test --release --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-%TARGET% fmt -- --check
|
||||
|
|
|
@ -28,13 +28,22 @@ x86_64-gnulinux:
|
|||
paths:
|
||||
- cargo/
|
||||
script:
|
||||
- cargo +beta-$TARGET clippy --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-$TARGET clippy --all-targets --features "fail-on-warnings az f16 serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16 std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings std"
|
||||
- cargo +beta-$TARGET check --all-targets --features fail-on-warnings
|
||||
- cargo +beta-$TARGET test --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde"
|
||||
|
@ -51,13 +60,22 @@ i686-gnulinux:
|
|||
paths:
|
||||
- cargo/
|
||||
script:
|
||||
- cargo +beta-$TARGET clippy --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-$TARGET clippy --all-targets --features "fail-on-warnings az f16 serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16 std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az f16"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings az"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16 std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings f16"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings serde std"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings serde"
|
||||
- cargo +beta-$TARGET check --all-targets --features "fail-on-warnings std"
|
||||
- cargo +beta-$TARGET check --all-targets --features fail-on-warnings
|
||||
- cargo +beta-$TARGET test --features "fail-on-warnings f16 serde"
|
||||
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde"
|
||||
|
|
|
@ -22,6 +22,7 @@ autobenches = false
|
|||
[features]
|
||||
f16 = ["half"]
|
||||
fail-on-warnings = []
|
||||
std = []
|
||||
|
||||
[dependencies]
|
||||
typenum = "1.10"
|
||||
|
@ -36,7 +37,7 @@ criterion = "0.3"
|
|||
num-traits = { version = "0.2", default-features = false }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["az", "f16", "serde"]
|
||||
features = ["az", "f16", "serde", "std"]
|
||||
|
||||
[[bench]]
|
||||
name = "bench_main"
|
||||
|
|
|
@ -190,7 +190,7 @@ The *fixed* crate requires rustc version 1.39.0 or later.
|
|||
|
||||
## Optional features
|
||||
|
||||
The *fixed* crate has three optional feature:
|
||||
The *fixed* crate has four optional feature:
|
||||
|
||||
1. `az`, disabled by default. This implements the cast traits
|
||||
provided by the [*az* crate].
|
||||
|
@ -199,6 +199,9 @@ The *fixed* crate has three optional feature:
|
|||
3. `serde`, disabled by default. This provides serialization support
|
||||
for the fixed-point types. This feature requires the
|
||||
[*serde* crate].
|
||||
4. `std`, disabled by default. This is for features that are not
|
||||
possible under `no_std`: currently the implementation of the
|
||||
[`Error`] trait for [`ParseFixedError`].
|
||||
|
||||
To enable features, you can add the dependency like this to
|
||||
[*Cargo.toml*]:
|
||||
|
@ -236,6 +239,7 @@ additional terms or conditions.
|
|||
[LICENSE-MIT]: https://opensource.org/licenses/MIT
|
||||
[`Binary`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Binary.html
|
||||
[`Display`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html
|
||||
[`Error`]: https://doc.rust-lang.org/nightly/std/error/trait.Error.html
|
||||
[`FixedI128`]: https://docs.rs/fixed/0.5.0/fixed/struct.FixedI128.html
|
||||
[`FixedI16`]: https://docs.rs/fixed/0.5.0/fixed/struct.FixedI16.html
|
||||
[`FixedI32`]: https://docs.rs/fixed/0.5.0/fixed/struct.FixedI32.html
|
||||
|
@ -257,6 +261,7 @@ additional terms or conditions.
|
|||
[`LossyInto`]: https://docs.rs/fixed/0.5.0/fixed/traits/trait.LossyInto.html
|
||||
[`LowerHex`]: https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html
|
||||
[`Octal`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Octal.html
|
||||
[`ParseFixedError`]: https://docs.rs/fixed/0.5.0/fixed/struct.ParseFixedError.html
|
||||
[`ToFixed`]: https://docs.rs/fixed/0.5.0/fixed/traits/trait.ToFixed.html
|
||||
[`U12`]: https://docs.rs/fixed/0.5.0/fixed/types/extra/type.U12.html
|
||||
[`U20F12`]: https://docs.rs/fixed/0.5.0/fixed/types/type.U20F12.html
|
||||
|
|
|
@ -27,6 +27,8 @@ use core::{
|
|||
ops::{Add, Mul, Shl, Shr},
|
||||
str::FromStr,
|
||||
};
|
||||
#[cfg(feature = "std")]
|
||||
use std::error::Error;
|
||||
|
||||
fn bin_str_int_to_bin<I>(bytes: &[u8]) -> (I, bool)
|
||||
where
|
||||
|
@ -543,16 +545,28 @@ impl From<ParseErrorKind> for ParseFixedError {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for ParseFixedError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
impl ParseFixedError {
|
||||
fn message(&self) -> &str {
|
||||
use self::ParseErrorKind::*;
|
||||
let message = match self.kind {
|
||||
match self.kind {
|
||||
InvalidDigit => "invalid digit found in string",
|
||||
NoDigits => "string has no digits",
|
||||
TooManyPoints => "more than one decimal point found in string",
|
||||
Overflow => "overflow",
|
||||
};
|
||||
Display::fmt(message, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ParseFixedError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self.message(), f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl Error for ParseFixedError {
|
||||
fn description(&self) -> &str {
|
||||
self.message()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -144,7 +144,7 @@ The *fixed* crate requires rustc version 1.39.0 or later.
|
|||
|
||||
## Optional features
|
||||
|
||||
The *fixed* crate has three optional feature:
|
||||
The *fixed* crate has four optional feature:
|
||||
|
||||
1. `az`, disabled by default. This implements the cast traits
|
||||
provided by the [*az* crate].
|
||||
|
@ -153,6 +153,9 @@ The *fixed* crate has three optional feature:
|
|||
3. `serde`, disabled by default. This provides serialization support
|
||||
for the fixed-point types. This feature requires the
|
||||
[*serde* crate].
|
||||
4. `std`, disabled by default. This is for features that are not
|
||||
possible under `no_std`: currently the implementation of the
|
||||
[`Error`] trait for [`ParseFixedError`].
|
||||
|
||||
To enable features, you can add the dependency like this to
|
||||
[*Cargo.toml*]:
|
||||
|
@ -190,6 +193,7 @@ additional terms or conditions.
|
|||
[LICENSE-MIT]: https://opensource.org/licenses/MIT
|
||||
[`Binary`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Binary.html
|
||||
[`Display`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html
|
||||
[`Error`]: https://doc.rust-lang.org/nightly/std/error/trait.Error.html
|
||||
[`FixedI128`]: struct.FixedI128.html
|
||||
[`FixedI16`]: struct.FixedI16.html
|
||||
[`FixedI32`]: struct.FixedI32.html
|
||||
|
@ -211,6 +215,7 @@ additional terms or conditions.
|
|||
[`LossyInto`]: traits/trait.LossyInto.html
|
||||
[`LowerHex`]: https://doc.rust-lang.org/nightly/core/fmt/trait.LowerHex.html
|
||||
[`Octal`]: https://doc.rust-lang.org/nightly/core/fmt/trait.Octal.html
|
||||
[`ParseFixedError`]: struct.ParseFixedError.html
|
||||
[`ToFixed`]: traits/trait.ToFixed.html
|
||||
[`U12`]: types/extra/type.U12.html
|
||||
[`U20F12`]: types/type.U20F12.html
|
||||
|
@ -225,14 +230,14 @@ additional terms or conditions.
|
|||
[`to_num`]: struct.FixedI32.html#method.to_num
|
||||
[const generics]: https://github.com/rust-lang/rust/issues/44580
|
||||
*/
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![warn(missing_docs)]
|
||||
#![doc(html_root_url = "https://docs.rs/fixed/0.5.0")]
|
||||
#![doc(test(attr(deny(warnings))))]
|
||||
#![cfg_attr(feature = "fail-on-warnings", deny(warnings))]
|
||||
#![allow(clippy::type_repetition_in_bounds)]
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(not(feature = "std"), test))]
|
||||
extern crate std;
|
||||
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in New Issue