Crates.io | cdumay_context |
lib.rs | cdumay_context |
version | 2.0.6 |
created_at | 2025-02-05 23:06:11.593939+00 |
updated_at | 2025-06-19 10:13:59.681815+00 |
description | A Rust Library for Context Manipulation and Export |
homepage | https://github.com/cdumay/cdumay_context |
repository | https://github.com/cdumay/cdumay_context |
max_upload_size | |
id | 1544843 |
size | 41,387 |
A flexible context management library that provides a trait-based approach for handling key-value data with support for multiple serialization formats.
Contextualize
trait and a Context
structcdumay_core::Error
structuse std::collections::BTreeMap;
use serde::{Serialize, Deserialize};
use cdumay_context::{Contextualize, Context};
// Basic usage
let mut ctx = Context::new();
ctx.insert("name".to_string(), serde_value::Value::String("Alice".to_string()));
The library provides a comprehensive error handling system through the Error
enum:
use cdumay_context::{Context, ContextDump, Contextualize, UnExpectedError};
use rand::Rng;
use serde::{Serialize, Deserialize};
use std::collections::BTreeMap;
fn example_error_handling() -> cdumay_core::Result<()> {
let mut rng = rand::rng();
let dice_roll: u8 = rng.random_range(1..=6);
let mut ctx = Context::new();
ctx.insert("env".to_string(), serde_value::Value::String("prod".to_string()));
// Generic error
if dice_roll == 7 {
return Err(UnExpectedError::new().with_message("Something went wrong".to_string()).with_details(ctx.dump()).into());
}
Ok(())
}