rune-framework 1.2.0

Official Rust SDK for Rune distributed function execution framework
Documentation
//! Execution context passed to rune handlers.

use std::collections::HashMap;

use tokio_util::sync::CancellationToken;

/// Execution context passed to every Rune handler invocation.
#[derive(Debug, Clone)]
pub struct RuneContext {
    /// Name of the Rune being invoked.
    pub rune_name: String,
    /// Unique request ID for this invocation.
    pub request_id: String,
    /// Arbitrary key-value context from the caller.
    pub context: HashMap<String, String>,
    /// Cancellation token that fires when the request is cancelled.
    pub cancellation: CancellationToken,
}

impl RuneContext {
    pub fn trace_id(&self) -> Option<&str> {
        self.context.get("trace_id").map(String::as_str)
    }

    pub fn parent_request_id(&self) -> Option<&str> {
        self.context.get("parent_request_id").map(String::as_str)
    }
}