Skip to content

Commit

Permalink
refactor from_str to fix irrefutable if let
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Oct 22, 2024
1 parent fe5c61b commit ad3492a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ impl FromStr for DataType {

/// Converts a string to a DataType (Boolean, Integer, Float, or String).
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Ok(b) = s.to_lowercase().parse::<bool>() {
let lower_s = s.to_lowercase();

if let Ok(b) = lower_s.parse::<bool>() {
Ok(DataType::Boolean(b))
} else if let Ok(i) = s.to_lowercase().parse::<i64>() {
} else if let Ok(i) = lower_s.parse::<i64>() {
Ok(DataType::Integer(i))
} else if let Ok(f) = s.to_lowercase().parse::<f64>() {
} else if let Ok(f) = lower_s.parse::<f64>() {
Ok(DataType::Float(f))
} else if let Ok(s) = s.to_lowercase().parse::<String>() {
} else if !lower_s.is_empty() {
Ok(DataType::String(format!("\"{}\"", s)))
} else {
Err("Invalid data type".to_string())
Expand Down

0 comments on commit ad3492a

Please sign in to comment.