2 unstable releases

0.2.0 Feb 5, 2023
0.1.0 Apr 7, 2022

#9 in #socket-address

Download history 15/week @ 2024-04-22 12/week @ 2024-04-29 24/week @ 2024-05-06 10/week @ 2024-05-13 26/week @ 2024-05-20 14/week @ 2024-05-27 16/week @ 2024-06-03 15/week @ 2024-06-10 13/week @ 2024-06-17 21/week @ 2024-06-24 4/week @ 2024-07-08 37/week @ 2024-07-15 14/week @ 2024-07-22 16/week @ 2024-07-29 87/week @ 2024-08-05

154 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–8MB
~145K SLoC