forked from M-Labs/thermostat
replace dependency lexical-core with num-traits
This commit is contained in:
parent
da4aaf4ff6
commit
e5b4789304
|
@ -20,6 +20,12 @@ dependencies = [
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bare-metal"
|
name = "bare-metal"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
|
@ -149,14 +155,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "857afb5ee9e767c3a73b2ad7212b6deea0c3761a27db1e20ea0ed57ee352cfef"
|
checksum = "857afb5ee9e767c3a73b2ad7212b6deea0c3761a27db1e20ea0ed57ee352cfef"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lexical-core"
|
name = "libm"
|
||||||
version = "0.7.4"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616"
|
checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a"
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
|
@ -195,6 +197,16 @@ dependencies = [
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"libm",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "panic-abort"
|
name = "panic-abort"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
|
@ -235,6 +247,12 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_version"
|
name = "rustc_version"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
@ -290,9 +308,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stm32f4"
|
name = "stm32f4"
|
||||||
version = "0.9.0"
|
version = "0.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "88640ad08c62e0651a1320187f38c3655d025ed580a10f0e4d85a2cc4829069f"
|
checksum = "44a3d6c58b14e63926273694e7dd644894513c5e35ce6928c4657ddb62cae976"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bare-metal",
|
"bare-metal",
|
||||||
"cortex-m",
|
"cortex-m",
|
||||||
|
@ -302,8 +320,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stm32f4xx-hal"
|
name = "stm32f4xx-hal"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
source = "git+https://github.com/thalesfragoso/stm32f4xx-hal?branch=pwm-impl#ef939935b90581553dc03f9146d05510b3ceba58"
|
source = "git+https://github.com/thalesfragoso/stm32f4xx-hal?branch=pwm-impl#cfd073e094daa9be9dd2b0a1f859a4e1c6be2b77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bare-metal",
|
"bare-metal",
|
||||||
"cast",
|
"cast",
|
||||||
|
@ -311,6 +329,7 @@ dependencies = [
|
||||||
"cortex-m-rt",
|
"cortex-m-rt",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
"nb",
|
"nb",
|
||||||
|
"rand_core",
|
||||||
"stm32f4",
|
"stm32f4",
|
||||||
"void",
|
"void",
|
||||||
]
|
]
|
||||||
|
@ -338,9 +357,9 @@ dependencies = [
|
||||||
"cortex-m-rt",
|
"cortex-m-rt",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
"hash2hwaddr",
|
"hash2hwaddr",
|
||||||
"lexical-core",
|
|
||||||
"log",
|
"log",
|
||||||
"nom",
|
"nom",
|
||||||
|
"num-traits",
|
||||||
"panic-abort",
|
"panic-abort",
|
||||||
"panic-semihosting",
|
"panic-semihosting",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
|
|
|
@ -30,7 +30,7 @@ hash2hwaddr = { version = "0.0", optional = true }
|
||||||
bit_field = "0.10"
|
bit_field = "0.10"
|
||||||
byteorder = { version = "1", default-features = false }
|
byteorder = { version = "1", default-features = false }
|
||||||
nom = { version = "5", default-features = false }
|
nom = { version = "5", default-features = false }
|
||||||
lexical-core = { version = "0.7", default-features = false }
|
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
semihosting = ["panic-semihosting", "cortex-m-log/semihosting"]
|
semihosting = ["panic-semihosting", "cortex-m-log/semihosting"]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use lexical_core::Float;
|
use num_traits::float::Float;
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
time::{MegaHertz, U32Ext},
|
time::{MegaHertz, U32Ext},
|
||||||
spi,
|
spi,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
use core::num::ParseIntError;
|
||||||
|
use core::str::{from_utf8, Utf8Error};
|
||||||
use nom::{
|
use nom::{
|
||||||
IResult,
|
IResult,
|
||||||
branch::alt,
|
branch::alt,
|
||||||
|
@ -9,7 +11,7 @@ use nom::{
|
||||||
multi::{fold_many0, fold_many1},
|
multi::{fold_many0, fold_many1},
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
};
|
};
|
||||||
use lexical_core as lexical;
|
use num_traits::{Num, ParseFloatError};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
@ -17,7 +19,10 @@ pub enum Error {
|
||||||
Parser(ErrorKind),
|
Parser(ErrorKind),
|
||||||
Incomplete,
|
Incomplete,
|
||||||
UnexpectedInput(u8),
|
UnexpectedInput(u8),
|
||||||
ParseNumber(lexical::Error)
|
Utf8(Utf8Error),
|
||||||
|
ParseInt(ParseIntError),
|
||||||
|
// `num_traits::ParseFloatError` does not impl Clone
|
||||||
|
ParseFloat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'t> From<nom::Err<(&'t [u8], ErrorKind)>> for Error {
|
impl<'t> From<nom::Err<(&'t [u8], ErrorKind)>> for Error {
|
||||||
|
@ -33,9 +38,21 @@ impl<'t> From<nom::Err<(&'t [u8], ErrorKind)>> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<lexical::Error> for Error {
|
impl From<Utf8Error> for Error {
|
||||||
fn from(e: lexical::Error) -> Self {
|
fn from(e: Utf8Error) -> Self {
|
||||||
Error::ParseNumber(e)
|
Error::Utf8(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseIntError> for Error {
|
||||||
|
fn from(e: ParseIntError) -> Self {
|
||||||
|
Error::ParseInt(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseFloatError> for Error {
|
||||||
|
fn from(_: ParseFloatError) -> Self {
|
||||||
|
Error::ParseFloat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +69,17 @@ impl fmt::Display for Error {
|
||||||
"parser: ".fmt(fmt)?;
|
"parser: ".fmt(fmt)?;
|
||||||
(e as &dyn core::fmt::Debug).fmt(fmt)
|
(e as &dyn core::fmt::Debug).fmt(fmt)
|
||||||
}
|
}
|
||||||
Error::ParseNumber(e) => {
|
Error::Utf8(e) => {
|
||||||
"parsing number: ".fmt(fmt)?;
|
"utf8: ".fmt(fmt)?;
|
||||||
(e as &dyn core::fmt::Debug).fmt(fmt)
|
(e as &dyn core::fmt::Debug).fmt(fmt)
|
||||||
}
|
}
|
||||||
|
Error::ParseInt(e) => {
|
||||||
|
"parsing int: ".fmt(fmt)?;
|
||||||
|
(e as &dyn core::fmt::Debug).fmt(fmt)
|
||||||
|
}
|
||||||
|
Error::ParseFloat => {
|
||||||
|
"parsing float".fmt(fmt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,8 +181,12 @@ fn whitespace(input: &[u8]) -> IResult<&[u8], ()> {
|
||||||
fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
|
fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
|
||||||
take_while1(is_digit)(input)
|
take_while1(is_digit)(input)
|
||||||
.map(|(input, digits)| {
|
.map(|(input, digits)| {
|
||||||
let result = lexical::parse(digits)
|
let result =
|
||||||
.map_err(|e| e.into());
|
from_utf8(digits)
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
.and_then(|digits| u32::from_str_radix(digits, 10)
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
);
|
||||||
(input, result)
|
(input, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -167,9 +195,13 @@ fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
|
||||||
let (input, sign) = opt(is_a("-"))(input)?;
|
let (input, sign) = opt(is_a("-"))(input)?;
|
||||||
let negative = sign.is_some();
|
let negative = sign.is_some();
|
||||||
let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?;
|
let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?;
|
||||||
let result = lexical::parse(digits)
|
let result =
|
||||||
.map(|result: f64| if negative { -result } else { result })
|
from_utf8(digits)
|
||||||
.map_err(|e| e.into());
|
.map_err(|e| e.into())
|
||||||
|
.and_then(|digits| f64::from_str_radix(digits, 10)
|
||||||
|
.map_err(|e| e.into())
|
||||||
|
)
|
||||||
|
.map(|result: f64| if negative { -result } else { result });
|
||||||
Ok((input, result))
|
Ok((input, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use lexical_core::Float;
|
use num_traits::float::Float;
|
||||||
|
|
||||||
/// Steinhart-Hart equation parameters
|
/// Steinhart-Hart equation parameters
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
Loading…
Reference in New Issue