From b0eafba0b8e8ce67268627c2cb863937306db2dd Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts <yoshuawuyts+github@gmail.com> Date: Sat, 26 Sep 2020 19:39:21 +0200 Subject: [PATCH] Fix lints --- src/cookies/middleware.rs | 2 +- src/endpoint.rs | 4 ++-- src/fs/serve_dir.rs | 2 +- src/lib.rs | 9 ++++----- src/listener/to_listener.rs | 3 ++- src/router.rs | 12 ++++++------ src/security/cors.rs | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/cookies/middleware.rs b/src/cookies/middleware.rs index cc9473cf7..145d24173 100644 --- a/src/cookies/middleware.rs +++ b/src/cookies/middleware.rs @@ -29,7 +29,7 @@ pub(crate) struct CookiesMiddleware; impl CookiesMiddleware { /// Creates a new `CookiesMiddleware`. - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self::default() } } diff --git a/src/endpoint.rs b/src/endpoint.rs index 48b08c0c6..0f741b273 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -67,7 +67,7 @@ where } } -pub struct MiddlewareEndpoint<E, State> { +pub(crate) struct MiddlewareEndpoint<E, State> { endpoint: E, middleware: Vec<Arc<dyn Middleware<State>>>, } @@ -96,7 +96,7 @@ where State: Clone + Send + Sync + 'static, E: Endpoint<State>, { - pub fn wrap_with_middleware(ep: E, middleware: &[Arc<dyn Middleware<State>>]) -> Self { + pub(crate) fn wrap_with_middleware(ep: E, middleware: &[Arc<dyn Middleware<State>>]) -> Self { Self { endpoint: ep, middleware: middleware.to_vec(), diff --git a/src/fs/serve_dir.rs b/src/fs/serve_dir.rs index 1dff4f46c..2fe793d5b 100644 --- a/src/fs/serve_dir.rs +++ b/src/fs/serve_dir.rs @@ -6,7 +6,7 @@ use async_std::path::PathBuf as AsyncPathBuf; use std::ffi::OsStr; use std::path::{Path, PathBuf}; -pub struct ServeDir { +pub(crate) struct ServeDir { prefix: String, dir: PathBuf, } diff --git a/src/lib.rs b/src/lib.rs index d487412bd..0cd6a6bf6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ #![cfg_attr(feature = "docs", feature(doc_cfg))] #![forbid(unsafe_code, rust_2018_idioms)] #![deny(future_incompatible, missing_debug_implementations, nonstandard_style)] -#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)] +#![warn(missing_docs, unreachable_pub)] #![doc(html_favicon_url = "https://yoshuawuyts.com/assets/http-rs/favicon.ico")] #![doc(html_logo_url = "https://yoshuawuyts.com/assets/http-rs/logo-rounded.png")] @@ -69,12 +69,11 @@ mod request; mod response; mod response_builder; mod route; +mod server; -#[cfg(not(feature = "__internal__bench"))] -mod router; -#[cfg(feature = "__internal__bench")] +// Expose the router for benchmarking only. +#[doc(hidden)] pub mod router; -mod server; pub mod convert; pub mod listener; diff --git a/src/listener/to_listener.rs b/src/listener/to_listener.rs index b67d068ba..b9f3774bb 100644 --- a/src/listener/to_listener.rs +++ b/src/listener/to_listener.rs @@ -47,9 +47,10 @@ use async_std::io; /// ``` /// # Other implementations /// See below for additional provided implementations of ToListener. - pub trait ToListener<State: Clone + Send + Sync + 'static> { + /// What listener are we converting into? type Listener: Listener<State>; + /// Transform self into a /// [`Listener`](crate::listener::Listener). Unless self is /// already bound/connected to the underlying io, converting to a diff --git a/src/router.rs b/src/router.rs index b3673ee7d..eb2ae0701 100644 --- a/src/router.rs +++ b/src/router.rs @@ -9,38 +9,38 @@ use crate::{Request, Response, StatusCode}; /// Internally, we have a separate state machine per http method; indexing /// by the method first allows the table itself to be more efficient. #[allow(missing_debug_implementations)] -pub struct Router<State> { +pub(crate) struct Router<State> { method_map: HashMap<http_types::Method, MethodRouter<Box<DynEndpoint<State>>>>, all_method_router: MethodRouter<Box<DynEndpoint<State>>>, } /// The result of routing a URL #[allow(missing_debug_implementations)] -pub struct Selection<'a, State> { +pub(crate) struct Selection<'a, State> { pub(crate) endpoint: &'a DynEndpoint<State>, pub(crate) params: Params, } impl<State: Clone + Send + Sync + 'static> Router<State> { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Router { method_map: HashMap::default(), all_method_router: MethodRouter::new(), } } - pub fn add(&mut self, path: &str, method: http_types::Method, ep: Box<DynEndpoint<State>>) { + pub(crate) fn add(&mut self, path: &str, method: http_types::Method, ep: Box<DynEndpoint<State>>) { self.method_map .entry(method) .or_insert_with(MethodRouter::new) .add(path, ep) } - pub fn add_all(&mut self, path: &str, ep: Box<DynEndpoint<State>>) { + pub(crate) fn add_all(&mut self, path: &str, ep: Box<DynEndpoint<State>>) { self.all_method_router.add(path, ep) } - pub fn route(&self, path: &str, method: http_types::Method) -> Selection<'_, State> { + pub(crate) fn route(&self, path: &str, method: http_types::Method) -> Selection<'_, State> { if let Some(Match { handler, params }) = self .method_map .get(&method) diff --git a/src/security/cors.rs b/src/security/cors.rs index 7ff913257..004a8d787 100644 --- a/src/security/cors.rs +++ b/src/security/cors.rs @@ -27,9 +27,9 @@ pub struct CorsMiddleware { max_age: HeaderValue, } -pub const DEFAULT_MAX_AGE: &str = "86400"; -pub const DEFAULT_METHODS: &str = "GET, POST, OPTIONS"; -pub const WILDCARD: &str = "*"; +pub(crate) const DEFAULT_MAX_AGE: &str = "86400"; +pub(crate) const DEFAULT_METHODS: &str = "GET, POST, OPTIONS"; +pub(crate) const WILDCARD: &str = "*"; impl CorsMiddleware { /// Creates a new Cors middleware.