Skip to content

Commit

Permalink
Core revamp part 3 (#255)
Browse files Browse the repository at this point in the history
Core revamp part 3
  • Loading branch information
fairingrey authored May 23, 2019
2 parents 32709f5 + 4d4ef6c commit d18c369
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 51 deletions.
12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -61,8 +55,10 @@ members = [
"tide-compression",
"tide-cookies",
"tide-core",
"tide-forms",
"tide-headers",
"tide-log",
"tide-querystring",
"tide-slog",
]

Expand Down
8 changes: 0 additions & 8 deletions src/error.rs

This file was deleted.

42 changes: 32 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,21 +19,44 @@
#[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,
err_fmt,
response,
App,
Context,
Endpoint,
EndpointResult,
Error,
Response,
Route,
Server,
// 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, ResultDynErrExt, ResultExt, 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;
}
9 changes: 0 additions & 9 deletions src/middleware.rs

This file was deleted.

3 changes: 3 additions & 0 deletions tide-compression/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions tide-cookies/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Crate that provides helpers and/or middlewares for Tide
//! related to cookies.
#![feature(async_await)]
#![warn(
nonstandard_style,
Expand Down
2 changes: 1 addition & 1 deletion tide-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*))
}
}

Expand Down
9 changes: 9 additions & 0 deletions tide-core/src/internal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! 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<EndpointResult<T>> + Send + 'static
pub type BoxTryFuture<T> =
Pin<Box<dyn Future<Output = crate::error::EndpointResult<T>> + Send + 'static>>;
5 changes: 5 additions & 0 deletions tide-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Core types and traits from Tide
#![feature(async_await, existential_type)]
#![warn(
nonstandard_style,
Expand All @@ -18,6 +20,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,
Expand Down
31 changes: 31 additions & 0 deletions tide-forms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = "../" }

16 changes: 12 additions & 4 deletions src/forms.rs → tide-forms/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
//! Crate that provides helpers and extensions for Tide
//! related to forms.
#![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},
Context, Response,
};
use tide_core::{err_fmt, error::ResultExt, internal::BoxTryFuture, Context, Response};

/// An extension trait for `Context`, providing form extraction.
pub trait ContextExt {
Expand Down
3 changes: 2 additions & 1 deletion tide-headers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tide-log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
31 changes: 31 additions & 0 deletions tide-querystring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

23 changes: 16 additions & 7 deletions src/querystring.rs → tide-querystring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use crate::{error::Error, Context};
//! Crate that provides helpers and extensions for Tide
//! related to query strings.
#![feature(async_await)]
#![warn(
nonstandard_style,
rust_2018_idioms,
future_incompatible,
missing_debug_implementations
)]

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> {
Expand All @@ -11,11 +22,9 @@ impl<'de, State> ContextExt<'de> for Context<State> {
#[inline]
fn url_query<T: Deserialize<'de>>(&'de self) -> Result<T, Error> {
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))?)
}
Expand All @@ -27,20 +36,20 @@ mod tests {
use futures::executor::block_on;
use http_service::Body;
use http_service_mock::make_server;
use serde_derive::Deserialize;
use serde::Deserialize;

#[derive(Deserialize)]
struct Params {
msg: String,
}

async fn handler(cx: crate::Context<()>) -> Result<String, Error> {
async fn handler(cx: tide::Context<()>) -> Result<String, Error> {
let p = cx.url_query::<Params>()?;
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
}
Expand Down
2 changes: 1 addition & 1 deletion tide-slog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tide-slog/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit d18c369

Please sign in to comment.