Skip to main content

Result

Type Alias Result 

Source
pub type Result<T> = Result<T, Error>;
Expand description

Convenient alias for std::result::Result<T, crate::errors::Error>.

All public API functions that can fail use this type. By importing crate::errors::Result, you can write:

use age_crypto::errors::Result;

fn my_function() -> Result<String> {
    // Return Ok with a value
    Ok(String::from("success"))
}

without needing to specify Error explicitly. The type is re‑exported from the crate root, so age_crypto::Result is also available.

§Example with error propagation

use age_crypto::{encrypt_with_passphrase, errors::Result};

fn process_and_encrypt(data: &str, pass: &str) -> Result<Vec<u8>> {
    // Any error from encrypt_with_passphrase is automatically
    // converted to our crate::errors::Error via the `?` operator
    let encrypted = encrypt_with_passphrase(data.as_bytes(), pass)?;
    Ok(encrypted.as_bytes().to_vec())
}

Aliased Type§

pub enum Result<T> {
    Ok(T),
    Err(Error),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(Error)

Contains the error value