pub struct Context<T = Value> { /* private fields */ }
Expand description
Immutable context with selfless love—holds data without judgment, returns fresh copies for changes. Generic type parameter T represents the current data shape, defaulting to serde_json::Value for flexibility.
Implementations§
Source§impl<T> Context<T>
impl<T> Context<T>
Sourcepub fn new(data: HashMap<String, Value>) -> Self
pub fn new(data: HashMap<String, Value>) -> Self
Create a new context with optional initial data
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
With gentle care, return the value or None, forgiving absence.
Sourcepub fn insert(self, key: String, value: Value) -> Context<T>
pub fn insert(self, key: String, value: Value) -> Context<T>
With selfless safety, return a fresh context with the addition (preserves type).
Sourcepub fn insert_as<U>(self, key: String, value: Value) -> Context<U>
pub fn insert_as<U>(self, key: String, value: Value) -> Context<U>
Type evolution: Transform to a new type while preserving data.
Sourcepub fn with_mutation(&self) -> MutableContext
pub fn with_mutation(&self) -> MutableContext
For those needing change, provide a mutable sibling.
Sourcepub fn merge(self, other: &Context<T>) -> Context<T>
pub fn merge(self, other: &Context<T>) -> Context<T>
Lovingly combine contexts, favoring the other with compassion.
Sourcepub fn to_hashmap(&self) -> HashMap<String, Value>
pub fn to_hashmap(&self) -> HashMap<String, Value>
Express as HashMap for ecosystem integration.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Context<T>
impl<'de, T> Deserialize<'de> for Context<T>
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<T> Freeze for Context<T>
impl<T> RefUnwindSafe for Context<T>where
T: RefUnwindSafe,
impl<T> Send for Context<T>where
T: Send,
impl<T> Sync for Context<T>where
T: Sync,
impl<T> Unpin for Context<T>where
T: Unpin,
impl<T> UnwindSafe for Context<T>where
T: UnwindSafe,
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