rust_cli_test/utils/
mod.rs

1use serde_json::Value;
2use uuid::Uuid;
3
4pub fn gen_uuid() -> String {
5    Uuid::new_v4()
6        .to_hyphenated()
7        .encode_lower(&mut Uuid::encode_buffer())
8        .to_owned()
9}
10
11pub fn or<T: Sized>(cond: bool, truth_val: T, false_val: T) -> T {
12    if cond {
13        truth_val
14    } else {
15        false_val
16    }
17}
18
19pub fn json_val_to_actual_str(val: &Value) -> String {
20    match val {
21        Value::String(ref s) => s.to_string(),
22        Value::Bool(i) => i.to_string(),
23        Value::Number(ref n) => n.to_string(),
24        Value::Null => "".to_owned(),
25        Value::Array(ref a) => {
26            let mut buf = String::new();
27            buf.push('[');
28            for i in a.iter() {
29                buf.push_str(json_val_to_actual_str(i).as_str());
30                buf.push_str(", ");
31            }
32            buf.push(']');
33            buf
34        }
35        Value::Object(_) => "[object]".to_owned(),
36    }
37}