1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use serde::de;

pub fn is_array<T: ?Sized>(type_name: &str) -> bool
    where
        T: de::DeserializeOwned {
    if type_name.starts_with("alloc::collections::linked_list")
        || type_name.starts_with("alloc::vec::Vec<")
        || type_name.starts_with("[")
        || type_name.starts_with("&[") {
        return true;
    }
    return false;
}

pub fn json_len(js: &serde_json::Value) -> usize {
    if js.is_null() {
        return 0;
    } else if js.is_array() {
        return js.as_array().unwrap().len();
    } else {
        return 1;
    }
}