Context

Struct Context 

Source
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.

This enables the context to be used in error reporting or structured logging without mutating the original instance.

Source§

impl Contextualize for Context

Source§

fn new() -> Self

Creates a new, empty Context.

Source§

fn insert(&mut self, k: String, v: Value)

Inserts a key-value pair into the context.

§Arguments
  • k - The key as a String.
  • v - The value as a serde_value::Value.
Source§

fn get(&self, k: &str) -> Option<&Value>

Retrieves a reference to a value associated with the given key.

§Arguments
  • k - The key as a string slice.
§Returns
  • Some(&Value) if the key exists, or None otherwise.
Source§

fn extend(&mut self, data: BTreeMap<String, Value>)

Extends the context with the given key-value pairs.

Existing keys will be overwritten.

§Arguments
  • data - A BTreeMap of key-value pairs to insert.
Source§

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 from_json(json: &str) -> Result<Self>

Creates a new context from a JSON string. Read more
Source§

fn to_json(&self, pretty: bool) -> Result<String>

Serializes the context to a JSON string. Read more
Source§

fn from_toml(toml: &str) -> Result<Self>

Creates a new context from a TOML string. Read more
Source§

fn to_toml(&self, pretty: bool) -> Result<String>

Serializes the context to a TOML string. Read more
Source§

fn from_yaml(yaml: &str) -> Result<Self>

Creates a new context from a YAML string. Read more
Source§

fn to_yaml(&self) -> Result<String>

Serializes the context to a YAML string. Read more
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Context

Source§

fn default() -> Context

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Context

Source§

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 Serialize for Context

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,