Crates.io | rocket-errors |
lib.rs | rocket-errors |
version | 0.1.0 |
source | src |
created_at | 2023-12-26 11:27:19.415194 |
updated_at | 2023-12-26 11:27:19.415194 |
description | A library for handling errors with anyhow and eyre in Rocket applications. |
homepage | |
repository | https://github.com/yuk1ty/rocket-errors |
max_upload_size | |
id | 1080851 |
size | 52,485 |
A crate that can handle anyhow
and eyre
on Rocket v0.5+.
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(())
}
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"] }
This project is licensed under the MIT license.