pub enum FactValue {
String(String),
Integer(i64),
Float(f64),
Boolean(bool),
Time(DateTime<FixedOffset>),
Object(HashMap<String, FactValue>),
Array(Vec<FactValue>),
Null,
}Expand description
A value rules can read and write. Integers and floats are distinct, as in Grule:
integer literals and arithmetic stay integers, and / always produces a float.
With serde, a FactValue uses the plain representation of its contents: strings,
numbers, booleans, null, arrays and maps, with times as RFC 3339 strings. When
deserializing, integers that fit in an i64 become Integer and other numbers
Float; strings always stay strings.
Variants§
String(String)
A string.
Integer(i64)
An integer.
Float(f64)
A floating-point number.
Boolean(bool)
true or false.
Time(DateTime<FixedOffset>)
A point in time, with its UTC offset.
Object(HashMap<String, FactValue>)
Named fields, like a struct or map.
Array(Vec<FactValue>)
A list of values.
Null
nil: no value.
Implementations§
Source§impl FactValue
impl FactValue
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
The value if it is an integer.
Sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
The value if it is a boolean.
Sourcepub fn as_time(&self) -> Option<&DateTime<FixedOffset>>
pub fn as_time(&self) -> Option<&DateTime<FixedOffset>>
The value if it is a time.
Sourcepub fn as_object(&self) -> Option<&HashMap<String, FactValue>>
pub fn as_object(&self) -> Option<&HashMap<String, FactValue>>
The fields if the value is an object.
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
The value’s type as rules and error messages describe it: "string",
"integer", "float", "boolean", "time", "object", "array" or "nil".
Sourcepub fn is_truthy(&self) -> bool
pub fn is_truthy(&self) -> bool
Whether the value is “truthy”: not nil, false, zero, or empty. (Rule conditions
themselves require booleans, as in Grule.)
Sourcepub fn from_serialize<T: Serialize + ?Sized>(
value: &T,
) -> Result<FactValue, String>
pub fn from_serialize<T: Serialize + ?Sized>( value: &T, ) -> Result<FactValue, String>
Converts any serializable value (typically a struct) into a fact value.
Structs and maps become objects, sequences become arrays, and integers that
fit in an i64 become integers. Time types serialize as strings.
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, String>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, String>
Converts this value back into a deserializable type. Times become RFC 3339 strings, and non-finite floats become null.