rocket-errors

Crates.iorocket-errors
lib.rsrocket-errors
version0.1.0
sourcesrc
created_at2023-12-26 11:27:19.415194
updated_at2023-12-26 11:27:19.415194
descriptionA library for handling errors with anyhow and eyre in Rocket applications.
homepage
repositoryhttps://github.com/yuk1ty/rocket-errors
max_upload_size
id1080851
size52,485
Yuki Toyoda (yuk1ty)

documentation

README

rocket-errors

A crate that can handle anyhow and eyre on Rocket v0.5+.

Usage example

Please see actual examples in the /examples directory.

anyhow

use rocket::{get, routes};
use rocket_errors::anyhow;

#[get("/")]
pub fn health_check() -> anyhow::Result<&'static str> {
    Ok("Hello, world!")
}

#[rocket::main]
async fn main() -> anyhow::Result<()> {
    let _ = rocket::build()
        .mount("/hc", routes![health_check])
        .launch()
        .await?;
    Ok(())
}

eyre

use rocket::{get, routes};
use rocket_errors::eyre;

#[get("/")]
pub fn health_check() -> eyre::Result<&'static str> {
    Ok("Hello, world!")
}

#[rocket::main]
async fn main() -> eyre::Result<()> {
    let _ = rocket::build()
        .mount("/hc", routes![health_check])
        .launch()
        .await?;
    Ok(())
}

Install

anyhow

anyhow is turned on by default. You just need to add a dependency to this crate:

rocket-errors = { version = "0.1" }

eyre

Using eyre is optional. You would like to use it, you need to add a dependency to this crate with a feature flag.

rocket-errors = { version = "0.1", features = ["eyre"] }

License

This project is licensed under the MIT license.

Commit count: 8

cargo fmt