From d67ec8f0857c5dac4fb779b68ef06b2d6d52c3d0 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 13 May 2019 21:03:16 +0530 Subject: [PATCH] isolate core revamp fix cargo fmt loosen up clippy to warnings on examples snipe dev deps from core eliminate some clippy warnings for examples add publish false, and remove publish requirements rename tide-examples to just examples --- Cargo.toml | 65 ++----------------- examples/Cargo.toml | 46 +++++++++++++ examples/{ => src}/body_types.rs | 4 +- examples/{ => src}/catch_all.rs | 4 +- examples/{ => src}/cookies.rs | 5 +- examples/{ => src}/default_headers.rs | 4 +- examples/{ => src}/graphql.rs | 5 +- examples/{ => src}/hello.rs | 4 +- examples/src/lib.rs | 13 ++++ examples/{ => src}/messages.rs | 4 +- .../main.rs => src/multipart_form/mod.rs} | 4 +- .../multipart_form}/test.txt | 0 examples/{ => src}/staticfile.rs | 6 +- tide/Cargo.toml | 52 +++++++++++++++ {src => tide/src}/app.rs | 0 {src => tide/src}/context.rs | 0 {src => tide/src}/cookies.rs | 0 {src => tide/src}/endpoint.rs | 0 {src => tide/src}/error.rs | 0 {src => tide/src}/forms.rs | 0 {src => tide/src}/lib.rs | 0 {src => tide/src}/middleware/cookies.rs | 0 .../src}/middleware/default_headers.rs | 0 {src => tide/src}/middleware/logger.rs | 0 {src => tide/src}/middleware/mod.rs | 0 {src => tide/src}/querystring.rs | 0 {src => tide/src}/response.rs | 0 {src => tide/src}/route.rs | 0 {src => tide/src}/router.rs | 0 {tests => tide/tests}/wildcard.rs | 0 30 files changed, 125 insertions(+), 91 deletions(-) create mode 100644 examples/Cargo.toml rename examples/{ => src}/body_types.rs (97%) rename examples/{ => src}/catch_all.rs (88%) rename examples/{ => src}/cookies.rs (95%) rename examples/{ => src}/default_headers.rs (89%) rename examples/{ => src}/graphql.rs (98%) rename examples/{ => src}/hello.rs (77%) create mode 100644 examples/src/lib.rs rename examples/{ => src}/messages.rs (98%) rename examples/{multipart-form/main.rs => src/multipart_form/mod.rs} (98%) rename examples/{multipart-form => src/multipart_form}/test.txt (100%) rename examples/{ => src}/staticfile.rs (98%) create mode 100644 tide/Cargo.toml rename {src => tide/src}/app.rs (100%) rename {src => tide/src}/context.rs (100%) rename {src => tide/src}/cookies.rs (100%) rename {src => tide/src}/endpoint.rs (100%) rename {src => tide/src}/error.rs (100%) rename {src => tide/src}/forms.rs (100%) rename {src => tide/src}/lib.rs (100%) rename {src => tide/src}/middleware/cookies.rs (100%) rename {src => tide/src}/middleware/default_headers.rs (100%) rename {src => tide/src}/middleware/logger.rs (100%) rename {src => tide/src}/middleware/mod.rs (100%) rename {src => tide/src}/querystring.rs (100%) rename {src => tide/src}/response.rs (100%) rename {src => tide/src}/route.rs (100%) rename {src => tide/src}/router.rs (100%) rename {tests => tide/tests}/wildcard.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index d90daaea7..78f2f7172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,65 +1,8 @@ -[package] -authors = [ - "Aaron Turon ", - "Yoshua Wuyts ", +[workspace] +members = [ + "tide", + "examples", ] -description = "WIP modular web framework" -documentation = "https://docs.rs/tide" -keywords = ["tide", "http", "web", "framework", "async"] -categories = [ - "network-programming", - "asynchronous", - "web-programming::http-server" -] -edition = "2018" -license = "MIT OR Apache-2.0" -name = "tide" -readme = "README.md" -repository = "https://github.com/rustasync/tide" -version = "0.2.0" - -[dependencies] -cookie = { version = "0.12", features = ["percent-encode"] } -futures-preview = "0.3.0-alpha.16" -fnv = "1.0.6" -http = "0.1" -http-service = "0.2.0" -pin-utils = "0.1.0-alpha.4" -route-recognizer = "0.1.12" -serde = "1.0.91" -serde_derive = "1.0.91" -serde_json = "1.0.39" -slog = "2.4.1" -slog-async = "2.3.0" -slog-term = "2.4.0" -typemap = "0.3.3" -serde_urlencoded = "0.5.5" - -[dependencies.http-service-hyper] -optional = true -version = "0.2.0" - -[dependencies.multipart] -default-features = false -features = ["server"] -version = "0.16.1" - -[features] -default = ["hyper"] -hyper = ["http-service-hyper"] - -[dev-dependencies] -basic-cookies = "0.1.3" -bytes = "0.4.12" -futures-fs = "0.0.5" -futures-util-preview = { version = "0.3.0-alpha.16", features = ["compat"] } -http-service-mock = "0.2.0" -juniper = "0.11.1" -mime = "0.3.13" -mime_guess = "2.0.0-alpha.6" -percent-encoding = "1.0.1" -serde = { version = "1.0.90", features = ["derive"] } -structopt = "0.2.15" [patch.crates-io] http-service = { git = "https://github.com/rustasync/http-service", branch = "master" } diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 000000000..54a73b1ff --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,46 @@ +[package] +authors = [ + "Tide Developers", +] +description = "Tide web server examples" +documentation = "https://docs.rs/tide" +edition = "2018" +license = "MIT OR Apache-2.0" +name = "examples" +readme = "README.md" +repository = "https://github.com/rustasync/tide" +version = "0.1.0" +publish = false + +[dependencies] +tide = { path = "../tide" } +cookie = { version = "0.12", features = ["percent-encode"] } +futures-preview = "0.3.0-alpha.16" +fnv = "1.0.6" +http = "0.1" +http-service = "0.2.0" +pin-utils = "0.1.0-alpha.4" +route-recognizer = "0.1.12" +serde_json = "1.0.39" +slog = "2.4.1" +slog-async = "2.3.0" +slog-term = "2.4.0" +typemap = "0.3.3" +serde_urlencoded = "0.5.5" +basic-cookies = "0.1.3" +bytes = "0.4.12" +futures-fs = "0.0.5" +futures-util-preview = { version = "0.3.0-alpha.16", features = ["compat"] } +http-service-mock = "0.2.0" +juniper = "0.11.1" +mime = "0.3.13" +mime_guess = "2.0.0-alpha.6" +percent-encoding = "1.0.1" +serde = { version = "1.0.91", features = ["derive"] } +structopt = "0.2.15" + +[dependencies.multipart] +default-features = false +features = ["server"] +version = "0.16.1" + diff --git a/examples/body_types.rs b/examples/src/body_types.rs similarity index 97% rename from examples/body_types.rs rename to examples/src/body_types.rs index 01c9b393c..0cc0e66a1 100644 --- a/examples/body_types.rs +++ b/examples/src/body_types.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use serde::{Deserialize, Serialize}; use tide::{ error::ResultExt, @@ -41,7 +39,7 @@ async fn echo_form(mut cx: Context<()>) -> EndpointResult { Ok(forms::form(msg)) } -fn main() { +pub fn main() { let mut app = App::new(); app.at("/echo/string").post(echo_string); diff --git a/examples/catch_all.rs b/examples/src/catch_all.rs similarity index 88% rename from examples/catch_all.rs rename to examples/src/catch_all.rs index 354ddbb03..69947f1f7 100644 --- a/examples/catch_all.rs +++ b/examples/src/catch_all.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use tide::Context; async fn echo_path(cx: Context<()>) -> String { @@ -7,7 +5,7 @@ async fn echo_path(cx: Context<()>) -> String { format!("Your path is: {}", path) } -fn main() { +pub fn main() { let mut app = tide::App::new(); app.at("/echo_path/*path").get(echo_path); app.serve("127.0.0.1:8000").unwrap(); diff --git a/examples/cookies.rs b/examples/src/cookies.rs similarity index 95% rename from examples/cookies.rs rename to examples/src/cookies.rs index 094030f27..4ebff0738 100644 --- a/examples/cookies.rs +++ b/examples/src/cookies.rs @@ -1,10 +1,7 @@ -#![feature(async_await)] - use cookie::Cookie; use tide::{cookies::ContextExt, middleware::CookiesMiddleware, Context}; /// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter. -/// async fn retrieve_cookie(mut cx: Context<()>) -> String { format!("hello cookies: {:?}", cx.get_cookie("hello").unwrap()) } @@ -19,7 +16,7 @@ async fn remove_cookie(mut cx: Context<()>) { cx.remove_cookie(Cookie::named("hello")).unwrap(); } -fn main() { +pub fn main() { let mut app = tide::App::new(); app.middleware(CookiesMiddleware::new()); diff --git a/examples/default_headers.rs b/examples/src/default_headers.rs similarity index 89% rename from examples/default_headers.rs rename to examples/src/default_headers.rs index 47f13a091..23f057e30 100644 --- a/examples/default_headers.rs +++ b/examples/src/default_headers.rs @@ -1,8 +1,6 @@ -#![feature(async_await)] - use tide::middleware::DefaultHeaders; -fn main() { +pub fn main() { let mut app = tide::App::new(); app.middleware( diff --git a/examples/graphql.rs b/examples/src/graphql.rs similarity index 98% rename from examples/graphql.rs rename to examples/src/graphql.rs index aeb9abfdf..7a263cbcf 100644 --- a/examples/graphql.rs +++ b/examples/src/graphql.rs @@ -2,9 +2,6 @@ // a look at [the Juniper book]. // // [the Juniper book]: https://graphql-rust.github.io/ - -#![feature(async_await)] - use http::status::StatusCode; use juniper::graphql_object; use std::sync::{atomic, Arc}; @@ -59,7 +56,7 @@ async fn handle_graphql(mut cx: Context) -> EndpointResult { Ok(resp) } -fn main() { +pub fn main() { let mut app = App::with_state(Data::default()); app.at("/graphql").post(handle_graphql); app.serve("127.0.0.1:8000").unwrap(); diff --git a/examples/hello.rs b/examples/src/hello.rs similarity index 77% rename from examples/hello.rs rename to examples/src/hello.rs index 030d394c1..83e246463 100644 --- a/examples/hello.rs +++ b/examples/src/hello.rs @@ -1,6 +1,4 @@ -#![feature(async_await)] - -fn main() { +pub fn main() { let mut app = tide::App::new(); app.at("/").get(async move |_| "Hello, world!"); app.serve("127.0.0.1:8000").unwrap(); diff --git a/examples/src/lib.rs b/examples/src/lib.rs new file mode 100644 index 000000000..31679fc28 --- /dev/null +++ b/examples/src/lib.rs @@ -0,0 +1,13 @@ +#![feature(async_await)] +#![warn(clippy::all)] +#![allow(dead_code)] + +mod body_types; +mod catch_all; +mod cookies; +mod default_headers; +mod graphql; +mod hello; +mod messages; +mod multipart_form; +mod staticfile; diff --git a/examples/messages.rs b/examples/src/messages.rs similarity index 98% rename from examples/messages.rs rename to examples/src/messages.rs index 7b8ef25dd..3ec8db93e 100644 --- a/examples/messages.rs +++ b/examples/src/messages.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use http::status::StatusCode; use serde::{Deserialize, Serialize}; use std::sync::Mutex; @@ -66,7 +64,7 @@ async fn get_message(cx: Context) -> EndpointResult { } } -fn main() { +pub fn main() { let mut app = App::with_state(Database::default()); app.at("/message").post(new_message); app.at("/message/:id").get(get_message).post(set_message); diff --git a/examples/multipart-form/main.rs b/examples/src/multipart_form/mod.rs similarity index 98% rename from examples/multipart-form/main.rs rename to examples/src/multipart_form/mod.rs index 14ca63639..fd3485b12 100644 --- a/examples/multipart-form/main.rs +++ b/examples/src/multipart_form/mod.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use serde::{Deserialize, Serialize}; use std::io::Read; use tide::{forms::ExtractForms, response, App, Context, EndpointResult}; @@ -57,7 +55,7 @@ async fn upload_file(mut cx: Context<()>) -> EndpointResult { Ok(response::json(message)) } -fn main() { +pub fn run() { let mut app = App::new(); app.at("/upload_file").post(upload_file); app.serve("127.0.0.1:8000").unwrap(); diff --git a/examples/multipart-form/test.txt b/examples/src/multipart_form/test.txt similarity index 100% rename from examples/multipart-form/test.txt rename to examples/src/multipart_form/test.txt diff --git a/examples/staticfile.rs b/examples/src/staticfile.rs similarity index 98% rename from examples/staticfile.rs rename to examples/src/staticfile.rs index 462a1f4bd..63524b36b 100644 --- a/examples/staticfile.rs +++ b/examples/src/staticfile.rs @@ -1,5 +1,3 @@ -#![feature(async_await)] - use bytes::Bytes; use futures_fs::FsPool; use futures_util::compat::*; @@ -44,7 +42,7 @@ impl StaticFile { // Check if the path exists and handle if it's a directory containing `index.html` if meta.is_some() && meta.as_ref().map(|m| !m.is_file()).unwrap_or(false) { // Redirect if path is a dir and URL doesn't end with "/" - if !actual_path.ends_with("/") { + if !actual_path.ends_with('/') { return Ok(response .status(StatusCode::MOVED_PERMANENTLY) .header(header::LOCATION, String::from(actual_path) + "/") @@ -121,7 +119,7 @@ async fn handle_path(ctx: Context) -> EndpointResult { }) } -fn main() { +pub fn main() { let mut app = App::with_state(StaticFile::new("./")); app.at("/*").get(handle_path); app.serve("127.0.0.1:8000").unwrap(); diff --git a/tide/Cargo.toml b/tide/Cargo.toml new file mode 100644 index 000000000..9e70bf5ea --- /dev/null +++ b/tide/Cargo.toml @@ -0,0 +1,52 @@ +[package] +authors = [ + "Aaron Turon ", + "Yoshua Wuyts ", +] +description = "WIP modular web framework" +documentation = "https://docs.rs/tide" +keywords = ["tide", "http", "web", "framework", "async"] +categories = [ + "network-programming", + "asynchronous", + "web-programming::http-server" +] +edition = "2018" +license = "MIT OR Apache-2.0" +name = "tide" +readme = "README.md" +repository = "https://github.com/rustasync/tide" +version = "0.2.0" + +[dependencies] +cookie = { version = "0.12", features = ["percent-encode"] } +futures-preview = "0.3.0-alpha.16" +fnv = "1.0.6" +http = "0.1" +http-service = "0.2.0" +pin-utils = "0.1.0-alpha.4" +route-recognizer = "0.1.12" +serde = "1.0.91" +serde_derive = "1.0.91" +serde_json = "1.0.39" +slog = "2.4.1" +slog-async = "2.3.0" +slog-term = "2.4.0" +typemap = "0.3.3" +serde_urlencoded = "0.5.5" + +[dependencies.http-service-hyper] +optional = true +version = "0.2.0" + +[dependencies.multipart] +default-features = false +features = ["server"] +version = "0.16.1" + +[features] +default = ["hyper"] +hyper = ["http-service-hyper"] + +[dev-dependencies] +http-service-mock = "0.2.0" diff --git a/src/app.rs b/tide/src/app.rs similarity index 100% rename from src/app.rs rename to tide/src/app.rs diff --git a/src/context.rs b/tide/src/context.rs similarity index 100% rename from src/context.rs rename to tide/src/context.rs diff --git a/src/cookies.rs b/tide/src/cookies.rs similarity index 100% rename from src/cookies.rs rename to tide/src/cookies.rs diff --git a/src/endpoint.rs b/tide/src/endpoint.rs similarity index 100% rename from src/endpoint.rs rename to tide/src/endpoint.rs diff --git a/src/error.rs b/tide/src/error.rs similarity index 100% rename from src/error.rs rename to tide/src/error.rs diff --git a/src/forms.rs b/tide/src/forms.rs similarity index 100% rename from src/forms.rs rename to tide/src/forms.rs diff --git a/src/lib.rs b/tide/src/lib.rs similarity index 100% rename from src/lib.rs rename to tide/src/lib.rs diff --git a/src/middleware/cookies.rs b/tide/src/middleware/cookies.rs similarity index 100% rename from src/middleware/cookies.rs rename to tide/src/middleware/cookies.rs diff --git a/src/middleware/default_headers.rs b/tide/src/middleware/default_headers.rs similarity index 100% rename from src/middleware/default_headers.rs rename to tide/src/middleware/default_headers.rs diff --git a/src/middleware/logger.rs b/tide/src/middleware/logger.rs similarity index 100% rename from src/middleware/logger.rs rename to tide/src/middleware/logger.rs diff --git a/src/middleware/mod.rs b/tide/src/middleware/mod.rs similarity index 100% rename from src/middleware/mod.rs rename to tide/src/middleware/mod.rs diff --git a/src/querystring.rs b/tide/src/querystring.rs similarity index 100% rename from src/querystring.rs rename to tide/src/querystring.rs diff --git a/src/response.rs b/tide/src/response.rs similarity index 100% rename from src/response.rs rename to tide/src/response.rs diff --git a/src/route.rs b/tide/src/route.rs similarity index 100% rename from src/route.rs rename to tide/src/route.rs diff --git a/src/router.rs b/tide/src/router.rs similarity index 100% rename from src/router.rs rename to tide/src/router.rs diff --git a/tests/wildcard.rs b/tide/tests/wildcard.rs similarity index 100% rename from tests/wildcard.rs rename to tide/tests/wildcard.rs