Skip to content

Commit a3b8168

Browse files
committed
Make the crate no_std-compliant, add "std" feature
1 parent 8af1ae2 commit a3b8168

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ authors = ["Ivan Smirnov <i.s.smirnov@gmail.com>"]
55
repository = "https://github.com/aldanor/fast-float-rust"
66
documentation = "https://docs.rs/fast-float"
77
description = "Fast floating-point number parser."
8-
keywords = ["parser", "parsing", "parse", "float"]
9-
categories = ["parser-implementations", "parsing", "text-processing", "algorithms"]
8+
keywords = ["parser", "parsing", "parse", "float", "no-std"]
9+
categories = ["parser-implementations", "parsing", "text-processing", "algorithms", "no-std"]
1010
readme = "README.md"
1111
license = "MIT OR Apache-2.0"
1212
autobenches = false
1313
edition = "2018"
1414
exclude = ["benches/*", "extras/*"]
1515

16+
[features]
17+
default = ["std"]
18+
std = []
19+
1620
[dev-dependencies]
1721
lexical-core = "0.7"
1822
criterion = "0.3"
@@ -37,3 +41,6 @@ members = [".", "extras/data-tests", "extras/simple-bench"]
3741
[profile.release]
3842
lto = "fat"
3943
codegen-units = 1
44+
45+
[package.metadata.docs.rs]
46+
features = ["std"]

src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::marker::PhantomData;
2-
use std::ptr;
1+
use core::marker::PhantomData;
2+
use core::ptr;
33

44
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55
pub struct AsciiStr<'a> {

src/float.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::fmt::{Debug, Display};
2-
use std::ops::{Add, Div, Mul, Neg};
1+
use core::fmt::{Debug, Display};
2+
use core::ops::{Add, Div, Mul, Neg};
33

44
mod private {
55
pub trait Sealed {}

src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
clippy::cargo_common_metadata
1212
)]
1313

14-
use std::error::Error as StdError;
15-
use std::fmt::{self, Display};
14+
use core::fmt::{self, Display};
1615

1716
mod binary;
1817
mod common;
@@ -32,10 +31,15 @@ impl Display for Error {
3231
}
3332
}
3433

35-
impl StdError for Error {}
34+
#[cfg(feature = "std")]
35+
impl std::error::Error for Error {
36+
fn description(&self) -> &str {
37+
"error while parsing a float"
38+
}
39+
}
3640

3741
/// Result type alias for fast-float parsing functions.
38-
pub type Result<T> = std::result::Result<T, Error>;
42+
pub type Result<T> = core::result::Result<T, Error>;
3943

4044
/// Trait for numerical float types that can be parsed from string.
4145
pub trait FastFloat: float::Float {

src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem;
1+
use core::mem;
22

33
use crate::binary::compute_float;
44
use crate::float::Float;

0 commit comments

Comments
 (0)