MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / compare_json

Function compare_json

nodedb/src/data/executor/handlers/sort_utils.rs:46–60  ·  view source on GitHub ↗
(a: &serde_json::Value, b: &serde_json::Value)

Source from the content-addressed store, hash-verified

44}
45
46fn compare_json(a: &serde_json::Value, b: &serde_json::Value) -> std::cmp::Ordering {
47 use serde_json::Value;
48 match (a, b) {
49 (Value::Null, Value::Null) => std::cmp::Ordering::Equal,
50 (Value::Null, _) => std::cmp::Ordering::Less,
51 (_, Value::Null) => std::cmp::Ordering::Greater,
52 (Value::Bool(x), Value::Bool(y)) => x.cmp(y),
53 (Value::Number(x), Value::Number(y)) => x
54 .as_f64()
55 .partial_cmp(&y.as_f64())
56 .unwrap_or(std::cmp::Ordering::Equal),
57 (Value::String(x), Value::String(y)) => x.cmp(y),
58 _ => a.to_string().cmp(&b.to_string()),
59 }
60}

Callers 1

sort_msgpack_rowsFunction · 0.70

Calls 4

to_stringMethod · 0.80
cmpMethod · 0.45
partial_cmpMethod · 0.45
as_f64Method · 0.45

Tested by

no test coverage detected