Type Alias Result

Source
pub type Result<T, E = Yoshi> = Result<T, E>;
Available on crate feature std only.
Expand description

Performance-optimized Result alias with mathematical precision guarantees.

This type alias simplifies the use of Result where the error type is fixed to Yoshi. It automatically adapts between std::result::Result and core::result::Result based on the enabled features.

§Examples

use yoshi_std::{Result, Yoshi, YoshiKind};

fn divide(a: f64, b: f64) -> Result<f64> {
    if b == 0.0 {
        return Err(Yoshi::new(YoshiKind::Validation {
            field: "divisor".into(),
            message: "Division by zero is not allowed".into(),
            expected: Some("non-zero".into()),
            actual: Some("0.0".into()),
        }));
    }
    Ok(a / b)
}

let result = divide(10.0, 2.0);
assert!(result.is_ok());
assert_eq!(result.unwrap(), 5.0);

let error_result = divide(10.0, 0.0);
assert!(error_result.is_err());

Aliased Type§

pub enum Result<T, E = Yoshi> {
    Ok(T),
    Err(E),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(E)

Contains the error value

Trait Implementations§

Source§

impl<T, E: Into<Yoshi>> Hatchable<T, E> for Result<T, E>

Source§

fn hatch(self) -> Hatch<T>

Converts an error into a Hatch<T> by mapping it into Yoshi. Read more