pub struct Fact {
pub name: String,
pub value: FactValue,
}Expand description
A named value rules can refer to, e.g. Ride in Ride.Distance > 5000.
Fields§
§name: StringThe name rules use for this fact.
value: FactValueThe fact’s value.
Implementations§
Source§impl Fact
impl Fact
Sourcepub fn set_field(
&mut self,
field_name: String,
value: FactValue,
) -> Result<(), String>
pub fn set_field( &mut self, field_name: String, value: FactValue, ) -> Result<(), String>
Sets a field of an object fact. Fails if the fact isn’t an object.
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, String>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, String>
Converts this fact’s value back into a deserializable type,
e.g. the struct it was created from with Fact::from_serialize.
Source§impl Fact
impl Fact
Sourcepub fn from_object(name: String, obj: HashMap<String, FactValue>) -> Self
pub fn from_object(name: String, obj: HashMap<String, FactValue>) -> Self
An object fact with the given fields.
Sourcepub fn from_serialize<T: Serialize + ?Sized>(
name: &str,
value: &T,
) -> Result<Self, String>
pub fn from_serialize<T: Serialize + ?Sized>( name: &str, value: &T, ) -> Result<Self, String>
Creates a fact from any serializable value, typically a struct.
Sourcepub fn string_fact(name: String, value: String) -> Self
pub fn string_fact(name: String, value: String) -> Self
A string fact.
Sourcepub fn integer_fact(name: String, value: i64) -> Self
pub fn integer_fact(name: String, value: i64) -> Self
An integer fact.
Sourcepub fn number_fact(name: String, value: f64) -> Self
pub fn number_fact(name: String, value: f64) -> Self
A float fact.
Sourcepub fn boolean_fact(name: String, value: bool) -> Self
pub fn boolean_fact(name: String, value: bool) -> Self
A boolean fact.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Fact
impl<'de> Deserialize<'de> for Fact
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Fact
impl RefUnwindSafe for Fact
impl Send for Fact
impl Sync for Fact
impl Unpin for Fact
impl UnsafeUnpin for Fact
impl UnwindSafe for Fact
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more