From 34cb65c4df352917431a8d90767ec9dd1475dc43 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 21 May 2019 21:32:12 +0530 Subject: [PATCH 1/6] refactor tide-forms, tide-querystring --- Cargo.toml | 12 +++---- src/error.rs | 8 ----- src/lib.rs | 31 +++++++++++++------ src/middleware.rs | 9 ------ tide-core/src/internal.rs | 8 +++++ tide-core/src/lib.rs | 3 ++ tide-forms/Cargo.toml | 31 +++++++++++++++++++ src/forms.rs => tide-forms/src/lib.rs | 14 +++++++-- tide-querystring/Cargo.toml | 31 +++++++++++++++++++ .../src/lib.rs | 15 ++++++--- 10 files changed, 120 insertions(+), 42 deletions(-) delete mode 100644 src/error.rs delete mode 100644 src/middleware.rs create mode 100644 tide-core/src/internal.rs create mode 100644 tide-forms/Cargo.toml rename src/forms.rs => tide-forms/src/lib.rs (90%) create mode 100644 tide-querystring/Cargo.toml rename src/querystring.rs => tide-querystring/src/lib.rs (91%) diff --git a/Cargo.toml b/Cargo.toml index 86801ad61..f977500a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,18 +27,12 @@ hyper = ["tide-core/http-service-hyper"] futures-preview = "0.3.0-alpha.16" http = "0.1" http-service = "0.2.0" -serde = "1.0.91" -serde_derive = "1.0.91" -serde_urlencoded = "0.5.5" tide-cookies = { path = "./tide-cookies", optional = true } tide-core = { path = "./tide-core" } tide-headers = { path = "./tide-headers" } tide-log = { path = "./tide-log" } - -[dependencies.multipart] -default-features = false -features = ["server"] -version = "0.16.1" +tide-forms = { path = "./tide-forms" } +tide-querystring = { path = "./tide-querystring" } [dev-dependencies] bytes = "0.4.12" @@ -61,8 +55,10 @@ members = [ "tide-compression", "tide-cookies", "tide-core", + "tide-forms", "tide-headers", "tide-log", + "tide-querystring", "tide-slog", ] diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 6f987973b..000000000 --- a/src/error.rs +++ /dev/null @@ -1,8 +0,0 @@ -use core::pin::Pin; -use futures::future::Future; - -pub use tide_core::error::{ - EndpointResult, Error, ResponseExt, ResultDynErrExt, ResultExt, StringError, -}; - -pub(crate) type BoxTryFuture = Pin> + Send + 'static>>; diff --git a/src/lib.rs b/src/lib.rs index 63609583a..cf3c600b2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![cfg_attr(any(feature = "nightly", test), feature(external_doc))] #![cfg_attr(feature = "nightly", doc(include = "../README.md"))] #![feature(async_await, existential_type)] -#![allow(unused_variables)] #![warn( nonstandard_style, rust_2018_idioms, @@ -20,21 +19,33 @@ #[doc(include = "../README.md")] const _README: () = (); -#[macro_use] -extern crate tide_core; +pub use http; #[cfg(feature = "cookies")] #[doc(inline)] pub use tide_cookies as cookies; -pub mod error; -pub mod forms; -pub mod middleware; -pub mod querystring; - #[doc(inline)] pub use tide_core::{ - response, App, Context, Endpoint, EndpointResult, Error, Response, Route, Server, + response, App, Context, Endpoint, EndpointResult, Error, Response, Route, Server, err_fmt + // TODO: export Body once it's in turn exported by tide_core }; -pub use http; +pub mod error { + pub use tide_core::error::{EndpointResult, Error, ResponseExt, ResultExt, ResultDynErrExt, StringError}; +} + +pub use tide_forms as forms; +pub use tide_querystring as querystring; + +pub mod middleware { + // Core + pub use tide_core::middleware::{Middleware, Next}; + + // Exports from tide repo. + pub use tide_headers::DefaultHeaders; + pub use tide_log::RequestLogger; + + #[cfg(feature = "cookies")] + pub use tide_cookies::CookiesMiddleware; +} \ No newline at end of file diff --git a/src/middleware.rs b/src/middleware.rs deleted file mode 100644 index 581792a7a..000000000 --- a/src/middleware.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Core -pub use tide_core::middleware::{Middleware, Next}; - -// Exports from tide repo. -pub use tide_headers::DefaultHeaders; -pub use tide_log::RequestLogger; - -#[cfg(feature = "cookies")] -pub use tide_cookies::CookiesMiddleware; diff --git a/tide-core/src/internal.rs b/tide-core/src/internal.rs new file mode 100644 index 000000000..3866fc5d0 --- /dev/null +++ b/tide-core/src/internal.rs @@ -0,0 +1,8 @@ +//! For internal use. These APIs will never be stable and +//! are meant to be used internally by the tide repo. + +use core::pin::Pin; +use futures::future::Future; + +/// Convenience alias for pinned box of Future> + Send + 'static +pub type BoxTryFuture = Pin> + Send + 'static>>; \ No newline at end of file diff --git a/tide-core/src/lib.rs b/tide-core/src/lib.rs index 4bd2d646a..c025d772e 100644 --- a/tide-core/src/lib.rs +++ b/tide-core/src/lib.rs @@ -18,6 +18,9 @@ pub mod response; mod route; mod router; +// Internal shared API for limited use across crates in our repo +pub mod internal; + pub use crate::{ app::{App, Server}, context::Context, diff --git a/tide-forms/Cargo.toml b/tide-forms/Cargo.toml new file mode 100644 index 000000000..3b5fe4a44 --- /dev/null +++ b/tide-forms/Cargo.toml @@ -0,0 +1,31 @@ +[package] +authors = [ + "Tide Developers" +] +description = "Form helpers and extensions for Tide" +documentation = "https://docs.rs/tide-forms" +keywords = ["tide", "web", "async", "helpers", "forms"] +categories = [ + "network-programming", + "web-programming::http-server", +] +edition = "2018" +license = "MIT OR Apache-2.0" +name = "tide-forms" +readme = "README.md" +repository = "https://github.com/rustasync/tide" +version = "0.1.0" + +[dependencies] +tide-core = { path = "../tide-core" } +http-service = "0.2.0" +futures-preview = "0.3.0-alpha.16" +http = "0.1" +log = "0.4.6" +multipart = { version = "0.16.1", features = ["server"], default-features = false } +serde = { version = "1.0.91", features = ["derive"] } +serde_urlencoded = "0.5.5" + +[dev-dependencies] +tide = { path = "../" } + diff --git a/src/forms.rs b/tide-forms/src/lib.rs similarity index 90% rename from src/forms.rs rename to tide-forms/src/lib.rs index ddfea6d7d..e8829405d 100644 --- a/src/forms.rs +++ b/tide-forms/src/lib.rs @@ -1,11 +1,21 @@ +#![feature(async_await)] +#![warn( + nonstandard_style, + rust_2018_idioms, + future_incompatible, + missing_debug_implementations +)] + use futures::prelude::*; use http_service::Body; use multipart::server::Multipart; use std::io::Cursor; -use crate::{ - error::{BoxTryFuture, ResultExt}, +use tide_core::{ + error::ResultExt, Context, Response, + err_fmt, + internal::BoxTryFuture }; /// An extension trait for `Context`, providing form extraction. diff --git a/tide-querystring/Cargo.toml b/tide-querystring/Cargo.toml new file mode 100644 index 000000000..5f5bbbd95 --- /dev/null +++ b/tide-querystring/Cargo.toml @@ -0,0 +1,31 @@ +[package] +authors = [ + "Tide Developers" +] +description = "Query string helpers and extensions for Tide" +documentation = "https://docs.rs/tide-querystring" +keywords = ["tide", "web", "async", "helpers", "querystring"] +categories = [ + "network-programming", + "web-programming::http-server", +] +edition = "2018" +license = "MIT OR Apache-2.0" +name = "tide-querystring" +readme = "README.md" +repository = "https://github.com/rustasync/tide" +version = "0.1.0" + + [dependencies] +tide-core = { path = "../tide-core" } +futures-preview = "0.3.0-alpha.16" +http = "0.1" +log = "0.4.6" +serde = { version = "1.0.91", features = ["derive"] } +serde_urlencoded = "0.5.5" + +[dev-dependencies] +tide = { path = "../" } +http-service = "0.2.0" +http-service-mock = "0.2.0" + diff --git a/src/querystring.rs b/tide-querystring/src/lib.rs similarity index 91% rename from src/querystring.rs rename to tide-querystring/src/lib.rs index 883108a32..d83076a21 100644 --- a/src/querystring.rs +++ b/tide-querystring/src/lib.rs @@ -1,4 +1,12 @@ -use crate::{error::Error, Context}; +#![feature(async_await)] +#![warn( + nonstandard_style, + rust_2018_idioms, + future_incompatible, + missing_debug_implementations +)] + +use tide_core::{error::Error, Context}; use http::StatusCode; use serde::Deserialize; @@ -8,14 +16,11 @@ pub trait ContextExt<'de> { } impl<'de, Data> ContextExt<'de> for Context { - #[inline] fn url_query>(&'de self) -> Result { let query = self.uri().query(); - if query.is_none() { return Err(Error::from(StatusCode::BAD_REQUEST)); } - Ok(serde_urlencoded::from_str(query.unwrap()) .map_err(|_| Error::from(StatusCode::BAD_REQUEST))?) } @@ -27,7 +32,7 @@ mod tests { use futures::executor::block_on; use http_service::Body; use http_service_mock::make_server; - use serde_derive::Deserialize; + use serde::de::Deserialize; #[derive(Deserialize)] struct Params { From 60834dc6e763ba6701619d8db1d069408017dc3c Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 22 May 2019 00:49:25 +0530 Subject: [PATCH 2/6] fix err_fmt macro --- tide-core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide-core/src/error.rs b/tide-core/src/error.rs index fa5d0db22..a64f53edd 100644 --- a/tide-core/src/error.rs +++ b/tide-core/src/error.rs @@ -16,7 +16,7 @@ impl std::fmt::Display for StringError { #[macro_export] macro_rules! err_fmt { {$($t:tt)*} => { - crate::error::StringError(format!($($t)*)) + $crate::error::StringError(format!($($t)*)) } } From d187372e7a765d8bbbfde006eb18d0942d1ebf69 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 22 May 2019 00:50:22 +0530 Subject: [PATCH 3/6] fix querystring tests --- tide-querystring/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tide-querystring/src/lib.rs b/tide-querystring/src/lib.rs index d83076a21..3fa9f2af5 100644 --- a/tide-querystring/src/lib.rs +++ b/tide-querystring/src/lib.rs @@ -1,3 +1,6 @@ +//! Crate that provides helpers and extensions for Tide +//! related to query strings. + #![feature(async_await)] #![warn( nonstandard_style, @@ -32,20 +35,20 @@ mod tests { use futures::executor::block_on; use http_service::Body; use http_service_mock::make_server; - use serde::de::Deserialize; + use serde::Deserialize; #[derive(Deserialize)] struct Params { msg: String, } - async fn handler(cx: crate::Context<()>) -> Result { + async fn handler(cx: tide::Context<()>) -> Result { let p = cx.url_query::()?; Ok(p.msg) } - fn app() -> crate::App<()> { - let mut app = crate::App::new(); + fn app() -> tide::App<()> { + let mut app = tide::App::new(); app.at("/").get(handler); app } From 676132e6c2f188c6670732058aa2cf05400c5c84 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 22 May 2019 00:59:52 +0530 Subject: [PATCH 4/6] add basic crate level doc --- tide-compression/src/lib.rs | 3 +++ tide-cookies/src/lib.rs | 3 +++ tide-core/src/lib.rs | 2 ++ tide-forms/src/lib.rs | 3 +++ tide-headers/src/lib.rs | 3 ++- tide-log/src/lib.rs | 4 ++-- tide-slog/src/lib.rs | 3 +++ 7 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tide-compression/src/lib.rs b/tide-compression/src/lib.rs index ec4a989a4..31f7327c2 100644 --- a/tide-compression/src/lib.rs +++ b/tide-compression/src/lib.rs @@ -1,3 +1,6 @@ +//! Crate that provides helpers and/or middlewares for Tide +//! related to compression. + #![cfg_attr(feature = "nightly", feature(external_doc))] #![cfg_attr(feature = "nightly", doc(include = "../README.md"))] #![feature(async_await)] diff --git a/tide-cookies/src/lib.rs b/tide-cookies/src/lib.rs index a2c37ef26..128b2d923 100644 --- a/tide-cookies/src/lib.rs +++ b/tide-cookies/src/lib.rs @@ -1,3 +1,6 @@ +//! Crate that provides helpers and/or middlewares for Tide +//! related to cookies. + #![feature(async_await)] #![warn( nonstandard_style, diff --git a/tide-core/src/lib.rs b/tide-core/src/lib.rs index c025d772e..2a38ab555 100644 --- a/tide-core/src/lib.rs +++ b/tide-core/src/lib.rs @@ -1,3 +1,5 @@ +//! Core types and traits from Tide + #![feature(async_await, existential_type)] #![warn( nonstandard_style, diff --git a/tide-forms/src/lib.rs b/tide-forms/src/lib.rs index e8829405d..4d8baf270 100644 --- a/tide-forms/src/lib.rs +++ b/tide-forms/src/lib.rs @@ -1,3 +1,6 @@ +//! Crate that provides helpers and extensions for Tide +//! related to forms. + #![feature(async_await)] #![warn( nonstandard_style, diff --git a/tide-headers/src/lib.rs b/tide-headers/src/lib.rs index 36b080567..1303ad1d0 100644 --- a/tide-headers/src/lib.rs +++ b/tide-headers/src/lib.rs @@ -1,5 +1,6 @@ -//! Crate that provides helpers, and/or middlewares for tide +//! Crate that provides helpers and/or middlewares for Tide //! related to http headers. + #![feature(async_await)] #![warn( nonstandard_style, diff --git a/tide-log/src/lib.rs b/tide-log/src/lib.rs index 88edf072b..9237d74b9 100644 --- a/tide-log/src/lib.rs +++ b/tide-log/src/lib.rs @@ -1,6 +1,6 @@ -//! Crate that provides helpers and/or middlewares for tide +//! Crate that provides helpers and/or middlewares for Tide //! related to logging. -//! + #![feature(async_await)] #![warn( nonstandard_style, diff --git a/tide-slog/src/lib.rs b/tide-slog/src/lib.rs index 1b1724fa7..04ef2e6ec 100644 --- a/tide-slog/src/lib.rs +++ b/tide-slog/src/lib.rs @@ -1,3 +1,6 @@ +//! Crate that provides helpers and/or middlewares for Tide +//! related to structured logging with slog. + #![feature(async_await)] #![warn( nonstandard_style, From d15bb7a026c0c179bec78e65213a6ae749645bf1 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 22 May 2019 01:01:08 +0530 Subject: [PATCH 5/6] cargo fmt --- src/lib.rs | 19 +++++++++++++++---- tide-core/src/internal.rs | 5 +++-- tide-core/src/lib.rs | 2 +- tide-forms/src/lib.rs | 7 +------ tide-querystring/src/lib.rs | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cf3c600b2..a67c722f7 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,12 +27,23 @@ pub use tide_cookies as cookies; #[doc(inline)] pub use tide_core::{ - response, App, Context, Endpoint, EndpointResult, Error, Response, Route, Server, err_fmt - // TODO: export Body once it's in turn exported by tide_core + err_fmt, + response, + App, + Context, + Endpoint, + EndpointResult, + Error, + Response, + Route, + Server, + // TODO: export Body once it's in turn exported by tide_core }; pub mod error { - pub use tide_core::error::{EndpointResult, Error, ResponseExt, ResultExt, ResultDynErrExt, StringError}; + pub use tide_core::error::{ + EndpointResult, Error, ResponseExt, ResultDynErrExt, ResultExt, StringError, + }; } pub use tide_forms as forms; @@ -48,4 +59,4 @@ pub mod middleware { #[cfg(feature = "cookies")] pub use tide_cookies::CookiesMiddleware; -} \ No newline at end of file +} diff --git a/tide-core/src/internal.rs b/tide-core/src/internal.rs index 3866fc5d0..9a2ad59f1 100644 --- a/tide-core/src/internal.rs +++ b/tide-core/src/internal.rs @@ -1,8 +1,9 @@ -//! For internal use. These APIs will never be stable and +//! For internal use. These APIs will never be stable and //! are meant to be used internally by the tide repo. use core::pin::Pin; use futures::future::Future; /// Convenience alias for pinned box of Future> + Send + 'static -pub type BoxTryFuture = Pin> + Send + 'static>>; \ No newline at end of file +pub type BoxTryFuture = + Pin> + Send + 'static>>; diff --git a/tide-core/src/lib.rs b/tide-core/src/lib.rs index 2a38ab555..ecdf21390 100644 --- a/tide-core/src/lib.rs +++ b/tide-core/src/lib.rs @@ -1,5 +1,5 @@ //! Core types and traits from Tide - + #![feature(async_await, existential_type)] #![warn( nonstandard_style, diff --git a/tide-forms/src/lib.rs b/tide-forms/src/lib.rs index 4d8baf270..67165c2e6 100644 --- a/tide-forms/src/lib.rs +++ b/tide-forms/src/lib.rs @@ -14,12 +14,7 @@ use http_service::Body; use multipart::server::Multipart; use std::io::Cursor; -use tide_core::{ - error::ResultExt, - Context, Response, - err_fmt, - internal::BoxTryFuture -}; +use tide_core::{err_fmt, error::ResultExt, internal::BoxTryFuture, Context, Response}; /// An extension trait for `Context`, providing form extraction. pub trait ContextExt { diff --git a/tide-querystring/src/lib.rs b/tide-querystring/src/lib.rs index 3fa9f2af5..b7ae83bdf 100644 --- a/tide-querystring/src/lib.rs +++ b/tide-querystring/src/lib.rs @@ -9,9 +9,9 @@ missing_debug_implementations )] -use tide_core::{error::Error, Context}; use http::StatusCode; use serde::Deserialize; +use tide_core::{error::Error, Context}; /// An extension trait for `Context`, providing query string deserialization. pub trait ContextExt<'de> { From 8ac86ec991fd85bb40c8caa1870d3c5f071ba861 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 22 May 2019 02:10:11 +0530 Subject: [PATCH 6/6] fix tide-slog keywords limit --- tide-slog/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tide-slog/Cargo.toml b/tide-slog/Cargo.toml index ca23079b8..dd00a8b04 100644 --- a/tide-slog/Cargo.toml +++ b/tide-slog/Cargo.toml @@ -4,7 +4,7 @@ authors = [ ] description = "Logging middleware for Tide based on slog" documentation = "https://docs.rs/tide-slog" -keywords = ["tide", "web", "async", "middleware", "logging", "slog"] +keywords = ["tide", "web", "middleware", "logging", "slog"] categories = [ "logging", "network-programming",