Trait LayContext

Source
pub trait LayContext<T> {
    // Required method
    fn lay(self, message: impl Into<String>) -> Hatch<T>;
}
Expand description

Trait that adds .lay(...) to Result<T, Yoshi>, enriching errors with context.

This trait provides ergonomic context attachment using thematic naming that aligns with the Yoshi metaphorical framework. The .lay() method is equivalent to adding context but uses intuitive, game-inspired terminology.

§Performance Characteristics

  • Context Addition: O(1) operation with minimal memory allocation
  • String Interning: Automatic optimization for repeated context messages
  • Memory Efficiency: Shared storage for common context patterns

§Examples

use yoshi_std::{Hatch, LayContext, Yoshi, YoshiKind};

fn database_operation() -> Hatch<String> {
    Err(Yoshi::new(YoshiKind::Internal {
        message: "connection failed".into(),
        source: None,
        component: None,
    }))
    .lay("While establishing database connection")
}

Required Methods§

Source

fn lay(self, message: impl Into<String>) -> Hatch<T>

Adds a contextual message to the error chain, like laying an egg with metadata.

This method enriches error information by attaching descriptive context that helps with debugging and error tracing. It uses thematic naming inspired by Yoshi’s egg-laying ability to create memorable, intuitive APIs.

§Arguments
  • message - The context message to attach. Accepts any type that converts to String.
§Returns

A Hatch<T> with the enriched context information attached.

§Performance
  • Time Complexity: O(1) for context attachment
  • Memory Optimization: Automatic string interning for efficiency
  • Allocation Pattern: Minimal heap allocation with shared storage
§Examples
use yoshi_std::{Hatch, LayContext, Yoshi, YoshiKind};

let result: Hatch<()> = Err(Yoshi::new(YoshiKind::Internal {
    message: "operation failed".into(),
    source: None,
    component: None,
}))
.lay("During user authentication");

assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.to_string().contains("During user authentication"));
§Errors

Returns the enriched Hatch<T> error if self is Err, or the original success value if self is Ok. This method never introduces new errors.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> LayContext<T> for Hatch<T>