pub struct ContextMap(pub HashMap<IdField, ContextValue>);Expand description
Typed values keyed by validated identifiers.
Wire values retain their type wrapper, for example
{"amount":{"number":100},"approved":{"boolean":true}}.
§Examples
use fluxpro_engine::models::context_map::context_map::{ContextMap, ContextMapBuilder, ContextValue};
use fluxpro_engine::models::id_field::IdField;
let amount = IdField::new("amount").unwrap();
let context = ContextMapBuilder::new()
.set(amount.clone(), ContextValue::number(100))
.build();
assert_eq!(context.as_number(&amount), Some(100));
assert_eq!(context.as_string(&amount), None);
let json = serde_json::to_value(&context).unwrap();
assert_eq!(json["amount"]["number"], 100);
let decoded: ContextMap = serde_json::from_value(json).unwrap();
assert_eq!(decoded, context);Tuple Fields§
§0: HashMap<IdField, ContextValue>Implementations§
Source§impl ContextMap
impl ContextMap
Sourcepub fn get(&self, key: &IdField) -> Option<&ContextValue>
pub fn get(&self, key: &IdField) -> Option<&ContextValue>
Borrows a value by its exact context key.
Source§impl ContextMap
impl ContextMap
Sourcepub fn apply_patcher(&mut self, patcher: &ContextPatcher)
pub fn apply_patcher(&mut self, patcher: &ContextPatcher)
Applies patch operations in order to this in-memory context.
Sourcepub fn as_string(&self, key: &IdField) -> Option<String>
pub fn as_string(&self, key: &IdField) -> Option<String>
Returns the string value, or None for an absent key or different type.
Sourcepub fn as_number(&self, key: &IdField) -> Option<i64>
pub fn as_number(&self, key: &IdField) -> Option<i64>
Returns the number value, or None for an absent key or different type.
Sourcepub fn as_id_field(&self, key: &IdField) -> Option<IdField>
pub fn as_id_field(&self, key: &IdField) -> Option<IdField>
Returns the id field value, or None for an absent key or different type.
Sourcepub fn as_float(&self, key: &IdField) -> Option<f64>
pub fn as_float(&self, key: &IdField) -> Option<f64>
Returns the float value, or None for an absent key or different type.
Sourcepub fn as_date(&self, key: &IdField) -> Option<NaiveDate>
pub fn as_date(&self, key: &IdField) -> Option<NaiveDate>
Returns the date value, or None for an absent key or different type.
Sourcepub fn as_date_time(&self, key: &IdField) -> Option<DateTime<Utc>>
pub fn as_date_time(&self, key: &IdField) -> Option<DateTime<Utc>>
Returns the date time value, or None for an absent key or different type.
Sourcepub fn as_bool(&self, key: &IdField) -> Option<bool>
pub fn as_bool(&self, key: &IdField) -> Option<bool>
Returns the bool value, or None for an absent key or different type.
Trait Implementations§
Source§impl Clone for ContextMap
impl Clone for ContextMap
Source§fn clone(&self) -> ContextMap
fn clone(&self) -> ContextMap
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContextMap
impl Debug for ContextMap
Source§impl Default for ContextMap
impl Default for ContextMap
Source§fn default() -> ContextMap
fn default() -> ContextMap
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for ContextMap
impl<'de> Deserialize<'de> for ContextMap
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
Source§impl PartialEq for ContextMap
impl PartialEq for ContextMap
Source§impl Serialize for ContextMap
impl Serialize for ContextMap
impl StructuralPartialEq for ContextMap
Auto Trait Implementations§
impl Freeze for ContextMap
impl RefUnwindSafe for ContextMap
impl Send for ContextMap
impl Sync for ContextMap
impl Unpin for ContextMap
impl UnsafeUnpin for ContextMap
impl UnwindSafe for ContextMap
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