viz-smol

Crates.ioviz-smol
lib.rsviz-smol
version0.1.9
sourcesrc
created_at2024-01-12 22:54:09.477318
updated_at2024-06-23 10:13:29.316718
descriptionAn adapter for smol runtime
homepagehttps://viz.rs
repositoryhttps://github.com/viz-rs/viz
max_upload_size
id1098105
size16,958
Fangdun Tsai (fundon)

documentation

https://docs.rs/viz-smol

README

Viz

Fast, robust, flexible, lightweight web framework for Rust

Safety! Docs.rs docs Crates.io version Download Codecov Discord

Features

  • Safety #![forbid(unsafe_code)]

  • Lightweight

  • Robust Routing

  • Handy Extractors

  • Simple + Flexible Handler & Middleware

  • Supports Tower Service

Hello Viz

use std::io;
use std::sync::Arc;

use async_net::TcpListener;
use macro_rules_attribute::apply;
use viz_smol::{IntoResponse, Request, Response, Result, Router};

async fn index(_: Request) -> Result<Response> {
    Ok("<h1>Hello, World!</h1>".into_response())
}

#[apply(smol_macros::main!)]
async fn main(ex: &Arc<smol_macros::Executor<'_>>) -> io::Result<()> {
    // Build our application with a route.
    let app = Router::new().get("/", index);

    // Create a `smol`-based TCP listener.
    let listener = TcpListener::bind(("127.0.0.1", 3000)).await.unwrap();
    println!("listening on {}", listener.local_addr().unwrap());

    // Run it
    viz_smol::serve(ex.clone(), listener, app).await
}

More examples can be found here.

Get started

Open Viz.rs, select language or version.

License

This project is licensed under the MIT license.

Author

Commit count: 458

cargo fmt