2 unstable releases

0.2.0 Feb 5, 2023
0.1.0 Apr 7, 2022

#11 in #throw

Download history 2/week @ 2024-11-17 2/week @ 2024-11-24 30/week @ 2024-12-08 27/week @ 2024-12-15 1/week @ 2024-12-22 28/week @ 2024-12-29 16/week @ 2025-01-05 25/week @ 2025-01-12 22/week @ 2025-01-19 10/week @ 2025-01-26 33/week @ 2025-02-02 34/week @ 2025-02-09 20/week @ 2025-02-16 22/week @ 2025-02-23 22/week @ 2025-03-02

102 downloads per month

MIT license

4KB

axum-error

cargo add axum-error

Provides an Error type which can be used in a eyre-like fashion for axum, as well as simple error handling with fehler.

use axum::{response::Html, routing::get, Router};
use std::{fs::read_to_string, net::SocketAddr};
use axum_error::*;
 
#[throws]
#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(index));
    axum::Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000)))
        .serve(app.into_make_service())
        .await?;
}
 
#[throws]
async fn index() -> Html<String> {
    Html(read_to_string("index.html")?)
}

lib.rs:

Provides an Error type which can be used in a eyre-like fashion for axum

use axum::{response::Html, routing::get, Router};
use std::{fs::read_to_string, net::SocketAddr};
use axum_error::Result;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(index));
    axum::Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000)))
        .serve(app.into_make_service())
        .await
        .unwrap()
}

async fn index() -> Result<Html<String>> {
    Ok(Html(read_to_string("index.html")?))
}

Dependencies

~6–13MB
~145K SLoC