diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 644bf7a6..f3b0205c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -55,7 +55,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@clippy - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + - run: cargo clippy --tests fmt: name: Fmt diff --git a/Cargo.toml b/Cargo.toml index 025fb5f5..598b6313 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,12 +61,13 @@ thiserror = "1.0" path-tree = "0.7" # http -headers = "0.3" -http = "0.2" -http-body = "=1.0.0-rc.2" -http-body-util = "=0.1.0-rc.3" -hyper = { version = "=1.0.0-rc.4", features = ["server"] } -hyper-util = { git = "https://github.com/hyperium/hyper-util", rev = "63e84bf", features = ["auto"] } +# TODO: wait headers-v1.0 +headers = { git = "https://github.com/hyperium/headers.git", rev = "4400aa9" } +http = "1" +http-body = "1" +http-body-util = "0.1" +hyper = { version = "1", features = ["server"] } +hyper-util = { version = "0.1", features = ["server-auto", "tokio"] } futures-util = "0.3" tokio = { version = "1.33", features = ["net"] } @@ -86,11 +87,12 @@ hex = "0.4" rust-embed = "8" # OpenTelemetry -opentelemetry = { version = "0.20", default-features = false } -opentelemetry-prometheus = { version = "0.13", features = [ +opentelemetry = { version = "0.21", default-features = false } +opentelemetry_sdk = { version = "0.21", default-features = false } +opentelemetry-prometheus = { version = "0.14", features = [ "prometheus-encoding", ] } -opentelemetry-semantic-conventions = { version = "0.12" } +opentelemetry-semantic-conventions = { version = "0.13" } prometheus = "0.13" # Tracing @@ -102,8 +104,25 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [profile.dev] +opt-level = 1 split-debuginfo = "unpacked" [profile.dev.package."*"] opt-level = 3 debug = false + +[workspace.lints.rust] +unsafe_code = "forbid" +rust_2018_idioms = "warn" +single_use_lifetimes = "warn" +non_ascii_idents = "warn" +unreachable_pub = "warn" +missing_debug_implementations = "warn" +missing_docs = "warn" + +[workspace.lints.clippy] +all = "deny" +pedantic = "deny" +module_name_repetitions = { level = "allow", priority = 1 } +too_many_lines = { level = "allow", priority = 1 } +type_complexity = { level = "allow", priority = 1 } diff --git a/clippy.toml b/clippy.toml index ad0ea4e7..938388da 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,2 @@ -msrv = "1.64" +# Clippy configuration +# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html diff --git a/examples/otel/metrics/Cargo.toml b/examples/otel/metrics/Cargo.toml index c577fbb1..853e4632 100644 --- a/examples/otel/metrics/Cargo.toml +++ b/examples/otel/metrics/Cargo.toml @@ -8,4 +8,5 @@ publish = false viz = { workspace = true, features = ["otel-metrics", "otel-prometheus"] } tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } -opentelemetry = { workspace = true, default-features = false, features = ["metrics"]} +opentelemetry = { workspace = true, features = ["metrics"]} +opentelemetry_sdk = { workspace = true, features = ["metrics"] } diff --git a/examples/otel/metrics/src/main.rs b/examples/otel/metrics/src/main.rs index af23ed30..237ae5d6 100644 --- a/examples/otel/metrics/src/main.rs +++ b/examples/otel/metrics/src/main.rs @@ -4,13 +4,10 @@ use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; -use opentelemetry::{ - global, - sdk::{ - metrics::{self, Aggregation, Instrument, MeterProvider, Stream}, - Resource, - }, - KeyValue, +use opentelemetry::{global, KeyValue}; +use opentelemetry_sdk::{ + metrics::{self, Aggregation, Instrument, MeterProvider, Stream}, + Resource, }; use viz::{ diff --git a/examples/otel/tracing/Cargo.toml b/examples/otel/tracing/Cargo.toml index 82154c54..e70e7dde 100644 --- a/examples/otel/tracing/Cargo.toml +++ b/examples/otel/tracing/Cargo.toml @@ -9,4 +9,5 @@ viz = { workspace = true, features = ["otel-tracing"] } tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } opentelemetry.workspace = true -opentelemetry-jaeger = { version = "0.19.0", features = ["rt-tokio-current-thread"]} +opentelemetry_sdk = { workspace = true, features = ["trace", "rt-tokio-current-thread"] } +opentelemetry-jaeger = { version = "0.20", features = ["rt-tokio-current-thread"]} diff --git a/examples/otel/tracing/src/main.rs b/examples/otel/tracing/src/main.rs index 1c34ea3b..b53fd236 100644 --- a/examples/otel/tracing/src/main.rs +++ b/examples/otel/tracing/src/main.rs @@ -1,10 +1,10 @@ #![deny(warnings)] #![allow(clippy::unused_async)] -use opentelemetry::{ - global, +use opentelemetry::global; +use opentelemetry_sdk::{ runtime::TokioCurrentThread, - sdk::{propagation::TraceContextPropagator, trace::Tracer}, + {propagation::TraceContextPropagator, trace::Tracer}, }; use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; diff --git a/examples/routing/openapi/Cargo.toml b/examples/routing/openapi/Cargo.toml index 9b7fa56b..c2daeaf6 100644 --- a/examples/routing/openapi/Cargo.toml +++ b/examples/routing/openapi/Cargo.toml @@ -12,5 +12,5 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } -utoipa = "4.0" -utoipa-swagger-ui = "4.0" +utoipa = "4" +utoipa-swagger-ui = "4" diff --git a/examples/templates/markup/Cargo.toml b/examples/templates/markup/Cargo.toml index d653cab0..ee497407 100644 --- a/examples/templates/markup/Cargo.toml +++ b/examples/templates/markup/Cargo.toml @@ -9,5 +9,5 @@ viz.workspace = true tokio = { workspace = true, features = [ "rt-multi-thread", "macros" ] } -markup = "0.13" +markup = "0.14" v_htmlescape = "0.15" diff --git a/examples/templates/markup/src/main.rs b/examples/templates/markup/src/main.rs index 7eaf7e87..6383c845 100644 --- a/examples/templates/markup/src/main.rs +++ b/examples/templates/markup/src/main.rs @@ -1,5 +1,7 @@ #![deny(warnings)] #![allow(clippy::unused_async)] +#![allow(clippy::must_use_candidate)] +#![allow(clippy::inherent_to_string_shadow_display)] use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index b64f6e3c..01ec3798 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -6,7 +6,7 @@ use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use tokio::sync::broadcast::{channel, Sender}; use viz::{ - get, serve, + get, serve_with_upgrades, types::{Message, Params, State, WebSocket}, HandlerExt, IntoHandler, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, Router, Tree, @@ -67,7 +67,7 @@ async fn main() -> Result<()> { let (stream, addr) = listener.accept().await?; let tree = tree.clone(); tokio::task::spawn(async move { - if let Err(err) = serve(stream, tree, Some(addr)).await { + if let Err(err) = serve_with_upgrades(stream, tree, Some(addr)).await { eprintln!("Error while serving HTTP connection: {err}"); } }); diff --git a/viz-core/Cargo.toml b/viz-core/Cargo.toml index 13605439..70e0a302 100644 --- a/viz-core/Cargo.toml +++ b/viz-core/Cargo.toml @@ -70,7 +70,7 @@ thiserror.workspace = true rfc7239 = "0.1" # realip cookie = { version = "0.18", features = ["percent-encode"], optional = true } -form-data = { version = "0.5.0-rc.2", optional = true } +form-data = { version = "0.5.0", optional = true } serde = { workspace = true, features = ["derive"], optional = true } serde_json = { workspace = true, optional = true } serde_urlencoded = { workspace = true, optional = true } @@ -105,3 +105,6 @@ tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/viz-core/src/lib.rs b/viz-core/src/lib.rs index 39aa6a4f..ac3c91b9 100644 --- a/viz-core/src/lib.rs +++ b/viz-core/src/lib.rs @@ -4,14 +4,6 @@ #![doc(html_logo_url = "https://viz.rs/logo.svg")] #![doc(html_favicon_url = "https://viz.rs/logo.svg")] -#![allow(clippy::module_name_repetitions)] -#![forbid(unsafe_code)] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] #![doc(test( no_crate_inject, attr( diff --git a/viz-core/src/middleware/cors.rs b/viz-core/src/middleware/cors.rs index 57791ea9..3ca29479 100644 --- a/viz-core/src/middleware/cors.rs +++ b/viz-core/src/middleware/cors.rs @@ -24,7 +24,6 @@ pub struct Config { allow_headers: HashSet, allow_origins: HashSet, expose_headers: HashSet, - #[allow(clippy::type_complexity)] origin_verify: Option bool + Send + Sync>>, } @@ -118,7 +117,6 @@ impl Config { } /// A function to verify the origin. If the function returns false, the request will be rejected. - #[allow(clippy::type_complexity)] #[must_use] pub fn origin_verify( mut self, diff --git a/viz-core/src/middleware/otel/tracing.rs b/viz-core/src/middleware/otel/tracing.rs index 127e6a4a..d60af86c 100644 --- a/viz-core/src/middleware/otel/tracing.rs +++ b/viz-core/src/middleware/otel/tracing.rs @@ -8,10 +8,8 @@ use http::uri::Scheme; use opentelemetry::{ global, propagation::Extractor, - trace::{ - FutureExt as OtelFutureExt, OrderMap, Span, SpanKind, Status, TraceContextExt, Tracer, - }, - Context, Key, Value, + trace::{FutureExt as OtelFutureExt, Span, SpanKind, Status, TraceContextExt, Tracer}, + Context, KeyValue, }; use opentelemetry_semantic_conventions::trace::{ CLIENT_ADDRESS, CLIENT_SOCKET_ADDRESS, EXCEPTION_MESSAGE, HTTP_REQUEST_BODY_SIZE, @@ -82,7 +80,7 @@ where .tracer .span_builder(format!("{} {}", req.method(), http_route)) .with_kind(SpanKind::Server) - .with_attributes_map(attributes) + .with_attributes(attributes) .start_with_context(&*self.tracer, &parent_context); span.add_event("request.started".to_string(), vec![]); @@ -143,7 +141,7 @@ impl<'a> RequestHeaderCarrier<'a> { } } -impl<'a> Extractor for RequestHeaderCarrier<'a> { +impl Extractor for RequestHeaderCarrier<'_> { fn get(&self, key: &str) -> Option<&str> { self.headers.get(key).and_then(|v| v.to_str().ok()) } @@ -153,62 +151,65 @@ impl<'a> Extractor for RequestHeaderCarrier<'a> { } } -fn build_attributes(req: &Request, http_route: &str) -> OrderMap { - let mut attributes = OrderMap::::with_capacity(10); +fn build_attributes(req: &Request, http_route: &str) -> Vec { + let mut attributes = Vec::with_capacity(10); // - attributes.insert(HTTP_ROUTE, http_route.to_string().into()); + attributes.push(KeyValue::new(HTTP_ROUTE, http_route.to_string())); // - attributes.insert(HTTP_REQUEST_METHOD, req.method().to_string().into()); - attributes.insert( + attributes.push(KeyValue::new(HTTP_REQUEST_METHOD, req.method().to_string())); + attributes.push(KeyValue::new( NETWORK_PROTOCOL_VERSION, - format!("{:?}", req.version()).into(), - ); + format!("{:?}", req.version()), + )); let remote_addr = req.remote_addr(); if let Some(remote_addr) = remote_addr { - attributes.insert(CLIENT_ADDRESS, remote_addr.to_string().into()); + attributes.push(KeyValue::new(CLIENT_ADDRESS, remote_addr.to_string())); } if let Some(realip) = req.realip().map(|value| value.0).filter(|realip| { remote_addr .map(SocketAddr::ip) .map_or(true, |remoteip| &remoteip != realip) }) { - attributes.insert(CLIENT_SOCKET_ADDRESS, realip.to_string().into()); + attributes.push(KeyValue::new(CLIENT_SOCKET_ADDRESS, realip.to_string())); } let uri = req.uri(); if let Some(host) = uri.host() { - attributes.insert(SERVER_ADDRESS, host.to_string().into()); + attributes.push(KeyValue::new(SERVER_ADDRESS, host.to_string())); } if let Some(port) = uri .port_u16() .map(i64::from) .filter(|port| *port != 80 && *port != 443) { - attributes.insert(SERVER_PORT, port.into()); + attributes.push(KeyValue::new(SERVER_PORT, port.to_string())); } if let Some(path_query) = uri.path_and_query() { if path_query.path() != "/" { - attributes.insert(URL_PATH, path_query.path().to_string().into()); + attributes.push(KeyValue::new(URL_PATH, path_query.path().to_string())); } if let Some(query) = path_query.query() { - attributes.insert(URL_QUERY, query.to_string().into()); + attributes.push(KeyValue::new(URL_QUERY, query.to_string())); } } - attributes.insert( + attributes.push(KeyValue::new( URL_SCHEME, - uri.scheme().unwrap_or(&Scheme::HTTP).to_string().into(), - ); + uri.scheme().unwrap_or(&Scheme::HTTP).to_string(), + )); if let Some(content_length) = req .content_length() .and_then(|len| i64::try_from(len).ok()) .filter(|len| *len > 0) { - attributes.insert(HTTP_REQUEST_BODY_SIZE, content_length.into()); + attributes.push(KeyValue::new( + HTTP_REQUEST_BODY_SIZE, + content_length.to_string(), + )); } if let Some(user_agent) = req @@ -216,7 +217,7 @@ fn build_attributes(req: &Request, http_route: &str) -> OrderMap { .as_ref() .map(UserAgent::as_str) { - attributes.insert(USER_AGENT_ORIGINAL, user_agent.to_string().into()); + attributes.push(KeyValue::new(USER_AGENT_ORIGINAL, user_agent.to_string())); } attributes diff --git a/viz-core/tests/handler.rs b/viz-core/tests/handler.rs index b404dbfd..ca582ca5 100644 --- a/viz-core/tests/handler.rs +++ b/viz-core/tests/handler.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] #![allow(clippy::unused_async)] #![allow(clippy::similar_names)] -#![allow(clippy::too_many_lines)] #![allow(clippy::wildcard_imports)] use http_body_util::Full; diff --git a/viz-core/tests/request.rs b/viz-core/tests/request.rs index 30f52e28..afaca620 100644 --- a/viz-core/tests/request.rs +++ b/viz-core/tests/request.rs @@ -4,10 +4,19 @@ use headers::{authorization::Bearer, Authorization, ContentType, HeaderValue}; use http::uri::Scheme; use serde::{Deserialize, Serialize}; use viz_core::{ - header::{AUTHORIZATION, CONTENT_TYPE, COOKIE, SET_COOKIE}, + // TODO: reqwest and hyper haven't used the same version of `http`. + // header::{AUTHORIZATION, CONTENT_TYPE, COOKIE, SET_COOKIE}, + // StatusCode, + header::CONTENT_TYPE, types::{self, PayloadError}, - Error, IncomingBody, IntoResponse, Request, RequestExt, Response, ResponseExt, Result, - StatusCode, + Error, + IncomingBody, + IntoResponse, + Request, + RequestExt, + Response, + ResponseExt, + Result, }; #[derive(Debug, Deserialize, Serialize, PartialEq)] @@ -62,7 +71,6 @@ fn request_ext() -> Result<()> { Ok(()) } -#[allow(clippy::too_many_lines)] #[tokio::test] async fn request_body() -> Result<()> { use futures_util::stream::TryStreamExt; @@ -70,6 +78,10 @@ async fn request_body() -> Result<()> { middleware::{cookie, limits}, Router, }; + use viz_test::http::{ + header::{AUTHORIZATION, COOKIE}, + StatusCode, + }; use viz_test::TestServer; let router = Router::new() @@ -300,6 +312,7 @@ async fn request_session() -> Result<()> { middleware::{cookie, helper::CookieOptions, session}, Router, }; + use viz_test::http::header::{COOKIE, SET_COOKIE}; use viz_test::{nano_id, sessions, TestServer}; let router = Router::new() diff --git a/viz-core/tests/type_payload.rs b/viz-core/tests/type_payload.rs index 233bca61..b8db5383 100644 --- a/viz-core/tests/type_payload.rs +++ b/viz-core/tests/type_payload.rs @@ -1,9 +1,10 @@ use std::collections::HashMap; -use viz_core::{types, Error, Request, RequestExt, Response, ResponseExt, Result, StatusCode}; +use viz_core::{types, Error, Request, RequestExt, Response, ResponseExt, Result}; #[tokio::test] async fn payload() -> Result<()> { use viz::{middleware::limits, Router}; + use viz_test::http::StatusCode; use viz_test::TestServer; let router = Router::new() diff --git a/viz-handlers/Cargo.toml b/viz-handlers/Cargo.toml index 7713b577..0b077150 100644 --- a/viz-handlers/Cargo.toml +++ b/viz-handlers/Cargo.toml @@ -66,3 +66,6 @@ tokio = { workspace = true, features = ["rt", "macros"] } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/viz-handlers/src/lib.rs b/viz-handlers/src/lib.rs index 7ec4742a..eb8843d8 100644 --- a/viz-handlers/src/lib.rs +++ b/viz-handlers/src/lib.rs @@ -2,13 +2,6 @@ #![doc(html_logo_url = "https://viz.rs/logo.svg")] #![doc(html_favicon_url = "https://viz.rs/logo.svg")] -#![forbid(unsafe_code)] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] #![doc(test( no_crate_inject, attr( diff --git a/viz-macros/Cargo.toml b/viz-macros/Cargo.toml index 127838e0..b206f019 100644 --- a/viz-macros/Cargo.toml +++ b/viz-macros/Cargo.toml @@ -28,3 +28,6 @@ tokio = { workspace = true, features = ["rt", "macros"] } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints] +workspace = true diff --git a/viz-macros/src/lib.rs b/viz-macros/src/lib.rs index 8e4a4f8e..d23e8dbe 100644 --- a/viz-macros/src/lib.rs +++ b/viz-macros/src/lib.rs @@ -27,13 +27,6 @@ #![doc(html_logo_url = "https://viz.rs/logo.svg")] #![doc(html_favicon_url = "https://viz.rs/logo.svg")] -#![forbid(unsafe_code)] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] #![doc(test( no_crate_inject, attr( diff --git a/viz-router/Cargo.toml b/viz-router/Cargo.toml index abddc76f..bae3bf21 100644 --- a/viz-router/Cargo.toml +++ b/viz-router/Cargo.toml @@ -30,3 +30,6 @@ serde_derive.workspace = true hyper.workspace = true http-body-util.workspace = true tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } + +[lints] +workspace = true diff --git a/viz-router/src/lib.rs b/viz-router/src/lib.rs index a9d17d56..f339ff62 100644 --- a/viz-router/src/lib.rs +++ b/viz-router/src/lib.rs @@ -2,13 +2,6 @@ #![doc(html_logo_url = "https://viz.rs/logo.svg")] #![doc(html_favicon_url = "https://viz.rs/logo.svg")] -#![forbid(unsafe_code)] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] #![doc(test( no_crate_inject, attr( diff --git a/viz-router/src/resources.rs b/viz-router/src/resources.rs index 21106f70..bd3ca803 100644 --- a/viz-router/src/resources.rs +++ b/viz-router/src/resources.rs @@ -254,7 +254,6 @@ impl IntoIterator for Resources { #[cfg(test)] #[allow(clippy::unused_async)] -#[allow(clippy::too_many_lines)] mod tests { use super::Kind; use crate::{get, Resources}; diff --git a/viz-router/src/route.rs b/viz-router/src/route.rs index 8d8d6d23..d9142ca2 100644 --- a/viz-router/src/route.rs +++ b/viz-router/src/route.rs @@ -212,7 +212,6 @@ impl fmt::Debug for Route { #[cfg(test)] #[allow(dead_code)] #[allow(clippy::unused_async)] -#[allow(clippy::too_many_lines)] mod tests { use super::Route; use http_body_util::BodyExt; diff --git a/viz-router/src/router.rs b/viz-router/src/router.rs index 2312032f..b98c1c05 100644 --- a/viz-router/src/router.rs +++ b/viz-router/src/router.rs @@ -182,7 +182,6 @@ impl Router { #[cfg(test)] #[allow(clippy::unused_async)] -#[allow(clippy::too_many_lines)] mod tests { use http_body_util::{BodyExt, Full}; use std::sync::Arc; diff --git a/viz-test/Cargo.toml b/viz-test/Cargo.toml index 7a7aa053..a46ea389 100644 --- a/viz-test/Cargo.toml +++ b/viz-test/Cargo.toml @@ -19,5 +19,6 @@ viz.workspace = true sessions = { version = "0.5", features = ["memory"] } nano-id = "0.3" +http = "0.2" reqwest = { version = "0.11", features = ["cookies", "json", "multipart"]} tokio = { workspace = true, features = ["full"] } diff --git a/viz-test/src/lib.rs b/viz-test/src/lib.rs index 169d06f8..7267bd22 100644 --- a/viz-test/src/lib.rs +++ b/viz-test/src/lib.rs @@ -3,6 +3,7 @@ use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use viz::{serve, Error, Result, Router, Tree}; +pub use http; pub use nano_id; pub use sessions; diff --git a/viz/Cargo.toml b/viz/Cargo.toml index 0421a38f..e1aaf52b 100644 --- a/viz/Cargo.toml +++ b/viz/Cargo.toml @@ -87,4 +87,5 @@ tokio = { workspace = true, features = ["macros", "rt", "rt-multi-thread"] } all-features = true rustdoc-args = ["--cfg", "docsrs"] -[package.metadata.playground] +[lints] +workspace = true diff --git a/viz/src/lib.rs b/viz/src/lib.rs index 2e7d912d..3ec2b174 100644 --- a/viz/src/lib.rs +++ b/viz/src/lib.rs @@ -514,13 +514,6 @@ #![doc(html_logo_url = "https://viz.rs/logo.svg")] #![doc(html_favicon_url = "https://viz.rs/logo.svg")] -#![forbid(unsafe_code)] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] #![doc(test( no_crate_inject, attr( @@ -538,7 +531,7 @@ pub use responder::Responder; #[cfg(any(feature = "http1", feature = "http2"))] mod serve; #[cfg(any(feature = "http1", feature = "http2"))] -pub use serve::serve; +pub use serve::{serve, serve_with_upgrades}; /// TLS pub mod tls; diff --git a/viz/src/serve.rs b/viz/src/serve.rs index cd4b62c9..0d9af2d3 100644 --- a/viz/src/serve.rs +++ b/viz/src/serve.rs @@ -18,7 +18,26 @@ where I: AsyncRead + AsyncWrite + Unpin + Send + 'static, { Builder::new(TokioExecutor::new()) - .serve_connection_with_upgrades(Io::new(stream).into_inner(), Responder::new(tree, addr)) + .serve_connection(Io::new(stream), Responder::new(tree, addr)) + .await + .map_err(Into::into) +} + +/// Serve the connections with upgrades. +/// +/// # Errors +/// +/// Will return `Err` if the connection does not be served. +pub async fn serve_with_upgrades( + stream: I, + tree: Arc, + addr: Option, +) -> Result<()> +where + I: AsyncRead + AsyncWrite + Unpin + Send + 'static, +{ + Builder::new(TokioExecutor::new()) + .serve_connection_with_upgrades(Io::new(stream), Responder::new(tree, addr)) .await .map_err(Into::into) } diff --git a/viz/src/tls.rs b/viz/src/tls.rs index 10479993..7907ad36 100644 --- a/viz/src/tls.rs +++ b/viz/src/tls.rs @@ -1,5 +1,3 @@ -#![allow(clippy::module_name_repetitions)] - mod listener; pub use listener::Listener;