Macro serde_json_lodash::find_last_index[][src]

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

Description can be found in lodash findLastIndex

Examples:

#[macro_use] extern crate serde_json_lodash;
use serde_json::json;
let users = json!([
  { "user": "barney",  "active": true },
  { "user": "fred",    "active": false },
  { "user": "pebbles", "active": false }
]);
assert_eq!(
  find_last_index!(users, |o| o["user"] == "pebbles".to_string()),
  json!(2)
);
// conflict with fn, no implemented
// assert_eq!(
//   find_last_index!(users, json!({ "user": "barney", "active": true })),
//   json!(0)
// );
// assert_eq!(
//   find_last_index!(users, json!(["active", false])),
//   json!(2)
// );
// assert_eq!(
//   find_last_index!(users, json!("active")),
//   json!(0)
// );
// assert_eq!(
//   find_last_index!(users, "active"),
//   json!(0)
// );

More examples:

assert_eq!(find_last_index!(), -1);
assert_eq!(find_last_index!(json!(null)), -1);
assert_eq!(find_last_index!(json!(true)), -1);
assert_eq!(find_last_index!(json!(0)), -1);
assert_eq!(find_last_index!(json!("")), -1);
assert_eq!(find_last_index!(json!([])), -1);
assert_eq!(find_last_index!(json!([{"a":null},{"a":false},{"a":0},{"a":""},{"a":[]}]), |_| true), 4);
assert_eq!(find_last_index!(json!([{"a":null},{"a":false},{"a":0},{"a":""},{"a":[]}]), |_| true, 1), 1);
assert_eq!(find_last_index!(json!([{"a":null},{"a":false},{"a":0},{"a":""},{"a":[]}]), |x| x == 0, 1), -1);
assert_eq!(find_last_index!(json!({})), -1);