Skip to main content

scalar

Function scalar 

Source
pub fn scalar(v: Option<&Value>) -> String
Expand description

One YAML scalar as the flattener would have written it: the text an awk comparison sees.

lib/yaml.sh flattens every value to a string, so order: 3 is "3", cancelled: true is "true" and a missing key is "". The index holds the same records as typed JSON, so the comparisons this module makes have to be made against the same text the awk compares — otherwise parallel_safe: false would be a bool here and the string "false" there, and only one of them would be right.

use majordomus_cli::plan::scalar;
use serde_json::json;
assert_eq!(scalar(Some(&json!(3))), "3");
assert_eq!(scalar(Some(&json!(true))), "true");
assert_eq!(scalar(Some(&json!("x"))), "x");
assert_eq!(scalar(Some(&json!(null))), "");
assert_eq!(scalar(None), "");