From ad3492a2a5ab050f0c160c46167bffa5834b78aa Mon Sep 17 00:00:00 2001 From: Jan Range Date: Tue, 22 Oct 2024 18:44:11 +0200 Subject: [PATCH] refactor `from_str` to fix irrefutable `if let` --- src/attribute.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/attribute.rs b/src/attribute.rs index b546dad..2692e39 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -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 { - if let Ok(b) = s.to_lowercase().parse::() { + let lower_s = s.to_lowercase(); + + if let Ok(b) = lower_s.parse::() { Ok(DataType::Boolean(b)) - } else if let Ok(i) = s.to_lowercase().parse::() { + } else if let Ok(i) = lower_s.parse::() { Ok(DataType::Integer(i)) - } else if let Ok(f) = s.to_lowercase().parse::() { + } else if let Ok(f) = lower_s.parse::() { Ok(DataType::Float(f)) - } else if let Ok(s) = s.to_lowercase().parse::() { + } else if !lower_s.is_empty() { Ok(DataType::String(format!("\"{}\"", s))) } else { Err("Invalid data type".to_string())