Skip to content

Commit

Permalink
support DataTypeRef for shared strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tafia committed Oct 25, 2023
1 parent d450d34 commit d898220
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 99 deletions.
38 changes: 38 additions & 0 deletions src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,44 @@ where
}
}

/// An enum to represent all different data types that can appear as
/// a value in a worksheet cell
#[derive(Debug, Clone, PartialEq, Default)]
pub enum DataTypeRef<'a> {
/// Signed integer
Int(i64),
/// Float
Float(f64),
/// String
String(String),
/// Shared String
SharedString(&'a str),
/// Boolean
Bool(bool),
/// Date or Time
DateTime(f64),
/// Error
Error(CellErrorType),
/// Empty cell
#[default]
Empty,
}

impl<'a> From<DataTypeRef<'a>> for DataType {
fn from(value: DataTypeRef<'a>) -> Self {
match value {
DataTypeRef::Int(v) => DataType::Int(v),
DataTypeRef::Float(v) => DataType::Float(v),
DataTypeRef::String(v) => DataType::String(v),
DataTypeRef::SharedString(v) => DataType::String(v.into()),
DataTypeRef::Bool(v) => DataType::Bool(v),
DataTypeRef::DateTime(v) => DataType::DateTime(v),
DataTypeRef::Error(v) => DataType::Error(v),
DataTypeRef::Empty => DataType::Empty,
}
}
}

#[cfg(all(test, feature = "dates"))]
mod tests {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mod de;
mod errors;
pub mod vba;

use datatype::DataTypeRef;
use serde::de::DeserializeOwned;
use std::borrow::Cow;
use std::cmp::{max, min};
Expand Down Expand Up @@ -217,6 +218,7 @@ where
pub trait CellType: Default + Clone + PartialEq {}

impl CellType for DataType {}
impl<'a> CellType for DataTypeRef<'a> {}
impl CellType for String {}
impl CellType for usize {} // for tests

Expand Down
Loading

0 comments on commit d898220

Please sign in to comment.