Skip to content

Commit

Permalink
clippy::or_fun_call
Browse files Browse the repository at this point in the history
warning: function call inside of `unwrap_or`
   --> src/cmd/validate.rs:957:68
    |
957 |                 Ok(float) => Value::Number(Number::from_f64(float).unwrap_or(Number::from(0))),
    |                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Number::from(0))`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
    = note: `-W clippy::or-fun-call` implied by `-W clippy::nursery`
    = help: to override `-W clippy::nursery` add `#[allow(clippy::or_fun_call)]`
  • Loading branch information
jqnatividad committed Oct 27, 2024
1 parent 5d0cf9f commit 258d57d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,9 @@ fn to_json_instance(
Err(_) => Value::String(String::from_utf8_lossy(value).into_owned()),
},
JSONtypes::Number => match fast_float::parse(value) {
Ok(float) => Value::Number(Number::from_f64(float).unwrap_or(Number::from(0))),
Ok(float) => {
Value::Number(Number::from_f64(float).unwrap_or_else(|| Number::from(0)))
},
Err(_) => {
return fail_clierror!(
"Can't cast into Number. key: {key}, value: {}",
Expand Down

0 comments on commit 258d57d

Please sign in to comment.