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