crispii_errors

Crates.iocrispii_errors
lib.rscrispii_errors
version1.0.0
created_at2025-03-14 19:26:15.013951+00
updated_at2025-09-01 18:06:02.302333+00
descriptionProvides a CrispiiError enum to be returned by any failing crispii functions.
homepage
repositoryhttps://github.com/stephen-paton/crispii_errors
max_upload_size
id1592640
size20,663
Stephen Paton (stephen-paton)

documentation

README

crispii_errors

crispii_errors is a simple crate, consisting of a single CrispiiError enum.

The basic idea is that this enum provides all possible failure outcomes of a function call, which can be returned as the Err(CrispiiError) variant of the Result type.

This pattern provides library creators and consumers with an easy way to share an understanding of how a function call could fail, allowing the library's consumer to decide how they wish to handle the failure case.

For example:

use crispii_errors::{
    enums::CrispiiError,
    structs::{
        ImpossibleOperationError,
    },
};

/// Adds 1 to num
/// Failure cases:
/// - ImpossibleOperationError -> Attempted to add 1 to a u8::MAX
fn add_one(num: u8) -> Result<u8, CrispiiError> {
    if num == u8::MAX {
        return Err(CrispiiError::ImpossibleOperation(ImpossibleOperationError::new("'num' is already equal to the maximum possible u8 value")));
    }

    Ok(num + 1)
}

let result = match add_one(u8::MAX) {
    Ok(val) => val,
    Err(crispii_error) => match crispii_error {
        CrispiiError::ImpossibleOperation(_) => u8::MAX,
        _ => panic!("No other variant of this error should be returned."),
    }
};

License: MIT OR Apache-2.0

Commit count: 7

cargo fmt