-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support smol runtime * chore: remove unless modules on smol example * feat: add a trait for limited request body (#130) * feat: add a trait for limited request body * fix: clippy * fix: export * chore: renaming * chore: remove redundance space lines * feat: add viz-smol * feat: add viz-smol * fix: docs * fix: docs * fix: docs
- Loading branch information
Showing
23 changed files
with
577 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "smol-example" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
viz-smol.workspace = true | ||
|
||
async-net.workspace = true | ||
smol-macros.workspace = true | ||
macro_rules_attribute.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::io; | ||
use std::sync::Arc; | ||
|
||
use async_net::TcpListener; | ||
use macro_rules_attribute::apply; | ||
use viz_smol::{IntoResponse, Request, Response, Result, Router}; | ||
|
||
#[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("/", handler); | ||
|
||
// 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 | ||
} | ||
|
||
async fn handler(_: Request) -> Result<Response> { | ||
Ok("<h1>Hello, World!</h1>".into_response()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
[package] | ||
name = "viz-smol" | ||
version = "0.1.0" | ||
documentation = "https://docs.rs/viz-smol" | ||
description = "An adapter for smol runtime" | ||
readme = "README.md" | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
rust-version.workspace = true | ||
|
||
[features] | ||
default = [ | ||
"state", | ||
"limits", | ||
"query", | ||
"form", | ||
"json", | ||
"multipart", | ||
"params", | ||
"cookie", | ||
"session", | ||
|
||
"http1", | ||
] | ||
|
||
state = ["viz-core/state"] | ||
limits = ["viz-core/limits"] | ||
|
||
query = ["viz-core/query"] | ||
form = ["viz-core/form"] | ||
json = ["viz-core/json"] | ||
multipart = ["viz-core/multipart"] | ||
params = ["viz-core/params"] | ||
|
||
cookie = ["viz-core/cookie"] | ||
cookie-private = ["viz-core/cookie-private"] | ||
cookie-signed = ["viz-core/cookie-signed"] | ||
|
||
session = ["cookie", "cookie-private", "viz-core/session"] | ||
|
||
csrf = ["cookie", "cookie-private", "viz-core/csrf"] | ||
cors = ["viz-core/cors"] | ||
|
||
http1 = ["hyper/http1"] | ||
http2 = ["hyper/http2"] | ||
|
||
unix-socket = [] | ||
|
||
macros = ["dep:viz-macros"] | ||
|
||
handlers = ["dep:viz-handlers"] | ||
|
||
otel = ["viz-core/otel"] | ||
otel-tracing = ["otel", "viz-core/otel-tracing"] | ||
otel-metrics = ["otel", "viz-core/otel-metrics"] | ||
otel-prometheus = ["handlers", "viz-handlers?/prometheus"] | ||
|
||
[dependencies] | ||
viz-core.workspace = true | ||
viz-router.workspace = true | ||
viz-handlers = { workspace = true, optional = true } | ||
viz-macros = { workspace = true, optional = true } | ||
|
||
hyper.workspace = true | ||
hyper-util.workspace = true | ||
tracing.workspace = true | ||
|
||
async-executor.workspace = true | ||
async-net.workspace = true | ||
smol-hyper.workspace = true | ||
futures-lite.workspace = true | ||
|
||
[dev-dependencies] | ||
smol-macros.workspace = true | ||
macro_rules_attribute.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//! Viz | ||
//! | ||
//! Fast, robust, flexible, lightweight web framework for Rust. | ||
//! | ||
//! # Features | ||
//! | ||
//! * **Safety** `#![forbid(unsafe_code)]` | ||
//! | ||
//! * Lightweight | ||
//! | ||
//! * Simple + Flexible [`Handler`](#handler) & [`Middleware`](#middleware) | ||
//! | ||
//! * Handy [`Extractors`](#extractors) | ||
//! | ||
//! * Robust [`Routing`](#routing) | ||
//! | ||
//! * Supports Tower [`Service`] | ||
//! | ||
//! # Hello Viz | ||
//! | ||
//! ```no_run | ||
//! 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 | ||
//! } | ||
//! ``` | ||
//! | ||
//! [`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html | ||
#![doc(html_logo_url = "https://viz.rs/logo.svg")] | ||
#![doc(html_favicon_url = "https://viz.rs/logo.svg")] | ||
#![doc(test( | ||
no_crate_inject, | ||
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) | ||
))] | ||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
|
||
mod responder; | ||
pub use responder::Responder; | ||
|
||
mod listener; | ||
pub use listener::Listener; | ||
|
||
mod server; | ||
pub use server::serve; | ||
|
||
#[cfg(any(feature = "native_tls", feature = "rustls"))] | ||
pub use server::tls; | ||
|
||
pub use viz_core::*; | ||
pub use viz_router::*; | ||
|
||
#[cfg(feature = "handlers")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "handlers")))] | ||
#[doc(inline)] | ||
pub use viz_handlers as handlers; | ||
|
||
#[cfg(feature = "macros")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] | ||
#[doc(inline)] | ||
pub use viz_macros::handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// A trait for a listener: `TcpListener` and `UnixListener`. | ||
pub trait Listener { | ||
/// The stream's type of this listener. | ||
type Io; | ||
/// The socket address type of this listener. | ||
type Addr; | ||
|
||
/// Accepts a new incoming connection from this listener. | ||
fn accept( | ||
&self, | ||
) -> impl std::future::Future<Output = std::io::Result<(Self::Io, Self::Addr)>> + Send; | ||
|
||
/// Returns the local address that this listener is bound to. | ||
/// | ||
/// # Errors | ||
/// | ||
/// An error will return if got the socket address of the local half of this connection is | ||
/// failed. | ||
fn local_addr(&self) -> std::io::Result<Self::Addr>; | ||
} |
Oops, something went wrong.