pub struct Context { /* private fields */ }Expand description
A dynamic key-value context container that can store heterogeneous data.
Internally uses a BTreeMap<String, serde_value::Value>, allowing you
to insert any serializable value while preserving insertion order and
allowing serialization/deserialization.
Trait Implementations§
Source§impl ContextDump for Context
Implements the ContextDump trait for the Context struct,
allowing the internal data map to be extracted as a clone.
impl ContextDump for Context
Implements the ContextDump trait for the Context struct,
allowing the internal data map to be extracted as a clone.
This enables the context to be used in error reporting or structured logging without mutating the original instance.
Source§impl Contextualize for Context
impl Contextualize for Context
Source§fn insert(&mut self, k: String, v: Value)
fn insert(&mut self, k: String, v: Value)
Inserts a key-value pair into the context.
§Arguments
k- The key as aString.v- The value as aserde_value::Value.
Source§fn extend(&mut self, data: BTreeMap<String, Value>)
fn extend(&mut self, data: BTreeMap<String, Value>)
Extends the context with the given key-value pairs.
Existing keys will be overwritten.
§Arguments
data- ABTreeMapof key-value pairs to insert.
Source§fn inner(&self) -> BTreeMap<String, Value>
fn inner(&self) -> BTreeMap<String, Value>
Returns a cloned copy of the internal map.
Useful for inspection or when you need owned data.
Source§fn to_json(&self, pretty: bool) -> Result<String>
fn to_json(&self, pretty: bool) -> Result<String>
Serializes the context to a JSON string. Read more
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
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 Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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