Macro serde_json_lodash::flatten_depth[][src]

macro_rules! flatten_depth {
    () => { ... };
    ($a:expr $(,)*) => { ... };
    ($a:expr, $b:expr $(,)*) => { ... };
    ($a:expr, $b:expr, $($rest:tt)*) => { ... };
}

Description can be found in lodash flattenDepth

Examples:

#[macro_use] extern crate serde_json_lodash;
use serde_json::json;
let array = json!([1, [2, [3, [4]], 5]]);
assert_eq!(
  flatten_depth!(array.clone(), 1),
  json!([1, 2, [3, [4]], 5])
);
assert_eq!(
  flatten_depth!(array.clone(), 2),
  json!([1, 2, 3, [4], 5])
);

More examples:

assert_eq!(flatten_depth!(), json!([]));
assert_eq!(flatten_depth!(json!(null)), json!([]));
assert_eq!(flatten_depth!(json!(false)), json!([]));
assert_eq!(flatten_depth!(json!(0)), json!([]));
assert_eq!(flatten_depth!(json!("")), json!([]));
assert_eq!(flatten_depth!(json!("ab")), json!(["a","b"]));
assert_eq!(flatten_depth!(json!("りしれ")), json!(["り","し","れ"]));
assert_eq!(flatten_depth!(json!({})), json!([]));
assert_eq!(flatten_depth!(json!({"a":1})), json!([]));
assert_eq!(flatten_depth!(json!([null,false,0,"",[null,[false]],{"a":1}])), json!([null,false,0,"",null,[false],{"a":1}]));
assert_eq!(flatten_depth!(json!([null,false,0,"",[null,[false]],{"a":1}]), 100), json!([null,false,0,"",null,false,{"a":1}]));
assert_eq!(flatten_depth!(json!([[[null]]]), 2), json!([null]));