in confidence/src/confidence_value.rs [214:265]
fn build_value() {
let alex = StructValue::default()
.with_field("is_male", false)
.with_field("id", 100)
.with_field("grade", 97.5)
.with_field("name", "Alex")
.with_field("friends", vec!["Bob", "Carl"])
.with_field(
"other",
StructValue::default().with_field("description", "A student"),
);
let is_male = alex.fields.get("is_male").unwrap();
assert!(is_male.is_bool());
assert_eq!(false, is_male.as_bool().unwrap());
let id = alex.fields.get("id").unwrap();
assert!(id.is_i64());
assert_eq!(100, id.as_i64().unwrap());
let grade = alex.fields.get("grade").unwrap();
assert!(grade.is_f64());
assert_eq!(97.5, grade.as_f64().unwrap());
let name = alex.fields.get("name").unwrap();
assert!(name.is_str());
assert_eq!("Alex", alex.fields.get("name").unwrap().as_str().unwrap());
let friends = alex.fields.get("friends").unwrap();
assert!(friends.is_array());
assert_eq!(
vec![
ConfidenceValue::String("Bob".to_string()),
ConfidenceValue::String("Carl".to_string())
],
*friends.as_array().unwrap()
);
let other = alex.fields.get("other").unwrap();
assert!(other.is_struct());
assert_eq!(
"A student",
other
.as_struct()
.unwrap()
.fields
.get("description")
.unwrap()
.as_str()
.unwrap()
);
}