1 个不稳定版本
0.1.0 | 2023年12月26日 |
---|
第 859 位在 HTTP 服务器
每月下载量 92 次
15KB
rocket-errors
一个可以在 Rocket v0.5+ 上处理 anyhow
和 eyre
的 Crate。
使用示例
请参阅 /examples
目录中的实际示例。
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
默认开启。您只需要添加对这个 Crate 的依赖
rocket-errors = { version = "0.1" }
eyre
使用 eyre
是可选的。如果您想使用它,您需要添加一个带有功能标志的依赖到这个 Crate。
rocket-errors = { version = "0.1", features = ["eyre"] }
许可证
本项目受 MIT 许可证 保护。
依赖项
约 15–46MB
约 784K SLoC