Expand description
Viz
Fast, robust, flexible, lightweight web framework for Rust.
§Features
-
Safety
#![forbid(unsafe_code)] -
Lightweight
-
Simple + Flexible
Handler&Middleware -
Handy
Extractors -
Robust
Routing -
Supports Tower
Service
§Hello Viz
use std::io;
use std::sync::Arc;
use async_net::TcpListener;
use macro_rules_attribute::apply;
use smol_macros::{Executor, main};
use viz_smol::{Request, Result, Router};
async fn index(_: Request) -> Result<&'static str> {
Ok("Hello, Viz!")
}
#[apply(main!)]
async fn main(ex: &Arc<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, listener, app).await
}Modules§
- future
- Asynchronous values.
- handler
- Traits and types for handling an HTTP.
- handlers
handlers - 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+SendboxedHandler. - Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Bytes
Mut - 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.
- Path
Tree - A path tree.
- Resources
- A resourceful route provides a mapping between HTTP verbs and URLs to handlers.
- Responder
- Handles the HTTP
Requestand retures the HTTPResponse. - Route
- A collection of verb-handler pair.
- Router
- A routes collection.
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Tree
- Store all final routes.
Enums§
- Body
- A body for HTTP
Requestand HTTPResponse. - Body
State - A body state.
- Error
- Represents errors that can occur handling application.
Traits§
- FnExt
- A handler with extractors.
- From
Request - An interface for extracting data from the HTTP
Request. - Future
- A future represents an asynchronous computation, commonly obtained by use of
async. - Handler
- A simplified asynchronous interface for handling input and output.
- Handler
Ext - The
HandlerExttrait, which provides adapters for chaining and composing handlers. - Http
Body - Trait representing a streaming body of a Request or Response.
- Into
Handler - The trait implemented by types that can be converted to a
Handler. - Into
Response - Trait implemented by types that can be converted to an HTTP
Response. - Listener
- A trait for a listener:
TcpListenerandUnixListener. - Request
Ext - The
RequestExtension. - Request
Limits Ext limits - The
RequestExtension with a limited body. - Response
Ext - The
ResponseExtension. - Transform
- Then
Transformtrait 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
CONNECTverb pair. - delete
- Creates a route with a handler and HTTP
DELETEverb pair. - get
- Creates a route with a handler and HTTP
GETverb pair. - head
- Creates a route with a handler and HTTP
HEADverb pair. - on
- Creates a route with a handler and HTTP verb pair.
- options
- Creates a route with a handler and HTTP
OPTIONSverb pair. - patch
- Creates a route with a handler and HTTP
PATCHverb pair. - post
- Creates a route with a handler and HTTP
POSTverb pair. - put
- Creates a route with a handler and HTTP
PUTverb pair. - serve
- Serve a server with smol’s networking types.
- trace
- Creates a route with a handler and HTTP
TRACEverb 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 - handler
macros - Transforms
extract-handlerto a Handler instance.