chisel_lexers/json/
numerics.rs

1/// A lazy numeric type which allows for raw bytes associated with a floating point value
2/// to be stashed away, and then only parsed when needed.  Structs of this type may be returned
3/// by the lexer if the associated feature is enabled
4#[derive(Debug, Clone, PartialEq)]
5pub struct LazyNumeric {
6    /// Raw bytes associated with the value
7    raw: Vec<u8>,
8}
9
10impl LazyNumeric {
11    /// Create a new struct given a raw byte slice
12    pub fn new(raw: &[u8]) -> Self {
13        LazyNumeric {
14            raw: Vec::from(raw),
15        }
16    }
17
18    /// Convenience method for conversion into an [f64]
19    pub fn to_float(&self) -> f64 {
20        fast_float::parse(self.raw.as_slice()).unwrap()
21    }
22}
23
24impl From<&LazyNumeric> for f64 {
25    fn from(value: &LazyNumeric) -> Self {
26        fast_float::parse(value.raw.as_slice()).unwrap()
27    }
28}
29
30impl From<LazyNumeric> for f64 {
31    fn from(value: LazyNumeric) -> Self {
32        fast_float::parse(value.raw.as_slice()).unwrap()
33    }
34}