diff --git a/README.md b/README.md index ec28bede..317bed5a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ where D: serde::Deserializer<'de>, { let data_type = calamine::DataType::deserialize(deserializer)?; - if let Some(float) = data_type.as_f64() { + if let Some(float) = data_type.as_float() { Ok(Some(float)) } else { Ok(None) @@ -85,7 +85,6 @@ fn main() -> Result<(), Box> { } ``` - ### Reader: Simple ```rust @@ -160,7 +159,7 @@ for s in sheets { ## Features -- `dates`: Add date related fn to `DataType`. +- `dates`: Add date related fn to `DataType`. - `picture`: Extract picture data. ### Others diff --git a/examples/excel_to_csv.rs b/examples/excel_to_csv.rs index 8e6d6e85..62fa7f18 100644 --- a/examples/excel_to_csv.rs +++ b/examples/excel_to_csv.rs @@ -39,7 +39,7 @@ fn write_range(dest: &mut W, range: &Range) -> std::io::Result<( write!(dest, "{}", s) } Data::Float(ref f) => write!(dest, "{}", f), - Data::DateTime(ref d) => write!(dest, "{}", d.as_f64()), + Data::DateTime(ref d) => write!(dest, "{}", d.as_float()), Data::Int(ref i) => write!(dest, "{}", i), Data::Error(ref e) => write!(dest, "{:?}", e), Data::Bool(ref b) => write!(dest, "{}", b), diff --git a/src/datatype.rs b/src/datatype.rs index e7ac200c..29f2a09b 100644 --- a/src/datatype.rs +++ b/src/datatype.rs @@ -138,7 +138,7 @@ impl DataType for Data { } } - fn as_i64(&self) -> Option { + fn as_int(&self) -> Option { match self { Data::Int(v) => Some(*v), Data::Float(v) => Some(*v as i64), @@ -147,7 +147,7 @@ impl DataType for Data { } } - fn as_f64(&self) -> Option { + fn as_float(&self) -> Option { match self { Data::Int(v) => Some(*v as f64), Data::Float(v) => Some(*v), @@ -446,7 +446,7 @@ impl DataType for DataRef<'_> { } } - fn as_i64(&self) -> Option { + fn as_int(&self) -> Option { match self { DataRef::Int(v) => Some(*v), DataRef::Float(v) => Some(*v as i64), @@ -456,7 +456,7 @@ impl DataType for DataRef<'_> { } } - fn as_f64(&self) -> Option { + fn as_float(&self) -> Option { match self { DataRef::Int(v) => Some(*v as f64), DataRef::Float(v) => Some(*v), @@ -525,10 +525,10 @@ pub trait DataType { fn as_string(&self) -> Option; /// Try converting data type into an int - fn as_i64(&self) -> Option; + fn as_int(&self) -> Option; /// Try converting data type into a float - fn as_f64(&self) -> Option; + fn as_float(&self) -> Option; /// Try converting data type into a date #[cfg(feature = "dates")] @@ -590,7 +590,7 @@ pub trait DataType { use std::str::FromStr; if self.is_int() || self.is_float() { - self.as_f64() + self.as_float() .map(|f| ExcelDateTime::from_value_only(f).as_datetime()) } else if self.is_datetime() { self.get_datetime().map(|d| d.as_datetime()) @@ -671,7 +671,7 @@ impl ExcelDateTime { } /// Converting data type into a float - pub fn as_f64(&self) -> f64 { + pub fn as_float(&self) -> f64 { self.value } diff --git a/src/de.rs b/src/de.rs index 34c0c94d..4957c528 100644 --- a/src/de.rs +++ b/src/de.rs @@ -560,7 +560,7 @@ impl<'a, 'de> serde::Deserializer<'de> for DataDeserializer<'a> { Data::Bool(v) => visitor.visit_bool(*v), Data::Int(v) => visitor.visit_i64(*v), Data::Empty => visitor.visit_unit(), - Data::DateTime(v) => visitor.visit_f64(v.as_f64()), + Data::DateTime(v) => visitor.visit_f64(v.as_float()), Data::DateTimeIso(v) => visitor.visit_str(v), Data::DurationIso(v) => visitor.visit_str(v), Data::Error(ref err) => Err(DeError::CellError { @@ -633,7 +633,7 @@ impl<'a, 'de> serde::Deserializer<'de> for DataDeserializer<'a> { Data::Empty => visitor.visit_bool(false), Data::Float(v) => visitor.visit_bool(*v != 0.), Data::Int(v) => visitor.visit_bool(*v != 0), - Data::DateTime(v) => visitor.visit_bool(v.as_f64() != 0.), + Data::DateTime(v) => visitor.visit_bool(v.as_float() != 0.), Data::DateTimeIso(_) => visitor.visit_bool(true), Data::DurationIso(_) => visitor.visit_bool(true), Data::Error(ref err) => Err(DeError::CellError {