ContextDump

Trait ContextDump 

Source
pub trait ContextDump {
    // Required method
    fn dump(&self) -> BTreeMap<String, Value>;
}
Expand description

A trait for types that can be converted into a serializable context map.

This trait defines a method dump that should return a BTreeMap where keys are strings and values are serde_value::Value. It is commonly used to extract structured debug or error context from a type in a generic and serializable form.

§Example

use serde_value::Value;
use std::collections::BTreeMap;
use cdumay_context::ContextDump;

struct MyContext {
    user_id: u32,
    action: String,
}

impl ContextDump for MyContext {
    fn dump(&self) -> BTreeMap<String, Value> {
        let mut map = BTreeMap::new();
        map.insert("user_id".to_string(), Value::U32(self.user_id));
        map.insert("action".to_string(), Value::String(self.action.clone()));
        map
    }
}

Required Methods§

Implementors§

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.