parsing numbers from strings
This commit is contained in:
parent
4a4e254759
commit
60434be505
12
src/main.rs
12
src/main.rs
|
@ -79,7 +79,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
sth = &sth[segment];
|
||||
}
|
||||
}
|
||||
let res_value = sth.as_f64().unwrap_or(0.0);
|
||||
|
||||
let mut res_value = sth.as_f64().unwrap_or(0.0);
|
||||
if sth.is_string() {
|
||||
res_value = match sth.as_str().unwrap().parse::<f64>() {
|
||||
Ok(val) => val,
|
||||
Err(_) => panic!("Conversion error on {}", sth)
|
||||
};
|
||||
}
|
||||
|
||||
let system = value["tags"]["system"].as_str().unwrap().to_string();
|
||||
let metric = value["tags"]["metric"].as_str().unwrap().to_string();
|
||||
let unit = value["tags"]["unit"].as_str().unwrap().to_string();
|
||||
|
@ -110,7 +118,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let write_result = client
|
||||
.query(write_queries)
|
||||
.await;
|
||||
assert!(write_result.is_ok(), "Write result was not okay");
|
||||
assert!(write_result.is_ok(), "{}", write_result.err().unwrap().to_string());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue