Crate viz_smol

Source
Expand description

Viz

Fast, robust, flexible, lightweight web framework for Rust.

§Features

§Hello Viz

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

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

async fn index(_: Request) -> Result<&'static str> {
    Ok("Hello, Viz!")
}

#[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
}

Modules§

future
Asynchronous values.
handler
Traits and types for handling an HTTP.
handlershandlers
A collection of handlers for Viz.
header
HTTP header types
headers
Typed HTTP Headers
middleware
Built-in Middleware.
types
Built-in Extractors types and traits.

Structs§

BoxHandler
A Clone + Send boxed Handler.
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
BytesMut
A unique reference to a contiguous slice of memory.
Incoming
A stream of Bytes, used when receiving bodies from the network.
Io
A wrapper that implements Tokio’s IO traits for an inner type that implements hyper’s IO traits, or vice versa (implements hyper’s IO traits for a type that implements Tokio’s IO traits).
Method
The Request Method (VERB)
Path
Matched route path infomation.
PathTree
A path tree.
Resources
A resourceful route provides a mapping between HTTP verbs and URLs to handlers.
Responder
Handles the HTTP Request and retures the HTTP Response.
Route
A collection of verb-handler pair.
Router
A routes collection.
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Tree
Store all final routes.

Enums§

Body
A body for HTTP Request and HTTP Response.
BodyState
A body state.
Error
Represents errors that can occur handling application.

Traits§

FnExt
A handler with extractors.
FromRequest
An interface for extracting data from the HTTP Request.
Future
A future represents an asynchronous computation obtained by use of async.
Handler
A simplified asynchronous interface for handling input and output.
HandlerExt
The HandlerExt trait, which provides adapters for chaining and composing handlers.
HttpBody
Trait representing a streaming body of a Request or Response.
IntoHandler
The trait implemented by types that can be converted to a Handler.
IntoResponse
Trait implemented by types that can be converted to an HTTP Response.
Listener
A trait for a listener: TcpListener and UnixListener.
RequestExt
The Request Extension.
RequestLimitsExt
The Request Extension with a limited body.
ResponseExt
The Response Extension.
Transform
Then Transform trait defines the interface of a handler factory that wraps inner handler to a Handler during construction.

Functions§

any
Creates a route with a handler and any HTTP verbs.
connect
Creates a route with a handler and HTTP CONNECT verb pair.
delete
Creates a route with a handler and HTTP DELETE verb pair.
get
Creates a route with a handler and HTTP GET verb pair.
head
Creates a route with a handler and HTTP HEAD verb pair.
on
Creates a route with a handler and HTTP verb pair.
options
Creates a route with a handler and HTTP OPTIONS verb pair.
patch
Creates a route with a handler and HTTP PATCH verb pair.
post
Creates a route with a handler and HTTP POST verb pair.
put
Creates a route with a handler and HTTP PUT verb pair.
serve
Serve a server with smol’s networking types.
trace
Creates a route with a handler and HTTP TRACE verb pair.

Type Aliases§

BoxError
An owned dynamically typed StdError.
Next
Represents a middleware parameter, which is a tuple that includes Requset and BoxHandler.
Request
Represents an HTTP Request.
Response
Represents an HTTP Response.
Result
Represents either success (Ok) or failure (Err).

Attribute Macros§

async_trait
handlermacros
Transforms extract-handler to a Handler instance.

Derive Macros§

ThisError