Macro serde_json_lodash::to_safe_integer
source · [−]macro_rules! to_safe_integer {
() => { ... };
($a:expr $(,)*) => { ... };
($a:expr, $($rest:tt)*) => { ... };
}
Expand description
Based on to_safe_integer()
Examples:
#[macro_use] extern crate serde_json_lodash;
use serde_json::json;
assert_eq!(
to_safe_integer!(json!(3.2)),
json!(3)
);
//assert_eq!(
// to_safe_integer!(json!(isize::MIN)), // serde_json will convert this to Number(-9223372036854775808)
// json!(0)
//);
//assert_eq!(
// to_safe_integer!(json!(f64::INFINITY)), // serde_json will convert this to Value::Null
// json!(9007199254740991) // serde_json will convert this to Number(-1)
//);
assert_eq!(
to_safe_integer!(json!("3.2")),
json!(3)
);
More examples:
assert_eq!(to_safe_integer!(), json!(0));