Skip to content

Commit d18c369

Browse files
authored
Core revamp part 3 (#255)
Core revamp part 3
2 parents 32709f5 + 4d4ef6c commit d18c369

File tree

17 files changed

+155
-51
lines changed

17 files changed

+155
-51
lines changed

Cargo.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,12 @@ hyper = ["tide-core/http-service-hyper"]
2727
futures-preview = "0.3.0-alpha.16"
2828
http = "0.1"
2929
http-service = "0.2.0"
30-
serde = "1.0.91"
31-
serde_derive = "1.0.91"
32-
serde_urlencoded = "0.5.5"
3330
tide-cookies = { path = "./tide-cookies", optional = true }
3431
tide-core = { path = "./tide-core" }
3532
tide-headers = { path = "./tide-headers" }
3633
tide-log = { path = "./tide-log" }
37-
38-
[dependencies.multipart]
39-
default-features = false
40-
features = ["server"]
41-
version = "0.16.1"
34+
tide-forms = { path = "./tide-forms" }
35+
tide-querystring = { path = "./tide-querystring" }
4236

4337
[dev-dependencies]
4438
bytes = "0.4.12"
@@ -61,8 +55,10 @@ members = [
6155
"tide-compression",
6256
"tide-cookies",
6357
"tide-core",
58+
"tide-forms",
6459
"tide-headers",
6560
"tide-log",
61+
"tide-querystring",
6662
"tide-slog",
6763
]
6864

src/error.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/lib.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![cfg_attr(any(feature = "nightly", test), feature(external_doc))]
22
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
33
#![feature(async_await, existential_type)]
4-
#![allow(unused_variables)]
54
#![warn(
65
nonstandard_style,
76
rust_2018_idioms,
@@ -20,21 +19,44 @@
2019
#[doc(include = "../README.md")]
2120
const _README: () = ();
2221

23-
#[macro_use]
24-
extern crate tide_core;
22+
pub use http;
2523

2624
#[cfg(feature = "cookies")]
2725
#[doc(inline)]
2826
pub use tide_cookies as cookies;
2927

30-
pub mod error;
31-
pub mod forms;
32-
pub mod middleware;
33-
pub mod querystring;
34-
3528
#[doc(inline)]
3629
pub use tide_core::{
37-
response, App, Context, Endpoint, EndpointResult, Error, Response, Route, Server,
30+
err_fmt,
31+
response,
32+
App,
33+
Context,
34+
Endpoint,
35+
EndpointResult,
36+
Error,
37+
Response,
38+
Route,
39+
Server,
40+
// TODO: export Body once it's in turn exported by tide_core
3841
};
3942

40-
pub use http;
43+
pub mod error {
44+
pub use tide_core::error::{
45+
EndpointResult, Error, ResponseExt, ResultDynErrExt, ResultExt, StringError,
46+
};
47+
}
48+
49+
pub use tide_forms as forms;
50+
pub use tide_querystring as querystring;
51+
52+
pub mod middleware {
53+
// Core
54+
pub use tide_core::middleware::{Middleware, Next};
55+
56+
// Exports from tide repo.
57+
pub use tide_headers::DefaultHeaders;
58+
pub use tide_log::RequestLogger;
59+
60+
#[cfg(feature = "cookies")]
61+
pub use tide_cookies::CookiesMiddleware;
62+
}

src/middleware.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

tide-compression/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Crate that provides helpers and/or middlewares for Tide
2+
//! related to compression.
3+
14
#![cfg_attr(feature = "nightly", feature(external_doc))]
25
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
36
#![feature(async_await)]

tide-cookies/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Crate that provides helpers and/or middlewares for Tide
2+
//! related to cookies.
3+
14
#![feature(async_await)]
25
#![warn(
36
nonstandard_style,

tide-core/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl std::fmt::Display for StringError {
1616
#[macro_export]
1717
macro_rules! err_fmt {
1818
{$($t:tt)*} => {
19-
crate::error::StringError(format!($($t)*))
19+
$crate::error::StringError(format!($($t)*))
2020
}
2121
}
2222

tide-core/src/internal.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! For internal use. These APIs will never be stable and
2+
//! are meant to be used internally by the tide repo.
3+
4+
use core::pin::Pin;
5+
use futures::future::Future;
6+
7+
/// Convenience alias for pinned box of Future<EndpointResult<T>> + Send + 'static
8+
pub type BoxTryFuture<T> =
9+
Pin<Box<dyn Future<Output = crate::error::EndpointResult<T>> + Send + 'static>>;

tide-core/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Core types and traits from Tide
2+
13
#![feature(async_await, existential_type)]
24
#![warn(
35
nonstandard_style,
@@ -18,6 +20,9 @@ pub mod response;
1820
mod route;
1921
mod router;
2022

23+
// Internal shared API for limited use across crates in our repo
24+
pub mod internal;
25+
2126
pub use crate::{
2227
app::{App, Server},
2328
context::Context,

tide-forms/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
authors = [
3+
"Tide Developers"
4+
]
5+
description = "Form helpers and extensions for Tide"
6+
documentation = "https://docs.rs/tide-forms"
7+
keywords = ["tide", "web", "async", "helpers", "forms"]
8+
categories = [
9+
"network-programming",
10+
"web-programming::http-server",
11+
]
12+
edition = "2018"
13+
license = "MIT OR Apache-2.0"
14+
name = "tide-forms"
15+
readme = "README.md"
16+
repository = "https://github.com/rustasync/tide"
17+
version = "0.1.0"
18+
19+
[dependencies]
20+
tide-core = { path = "../tide-core" }
21+
http-service = "0.2.0"
22+
futures-preview = "0.3.0-alpha.16"
23+
http = "0.1"
24+
log = "0.4.6"
25+
multipart = { version = "0.16.1", features = ["server"], default-features = false }
26+
serde = { version = "1.0.91", features = ["derive"] }
27+
serde_urlencoded = "0.5.5"
28+
29+
[dev-dependencies]
30+
tide = { path = "../" }
31+

src/forms.rs renamed to tide-forms/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! Crate that provides helpers and extensions for Tide
2+
//! related to forms.
3+
4+
#![feature(async_await)]
5+
#![warn(
6+
nonstandard_style,
7+
rust_2018_idioms,
8+
future_incompatible,
9+
missing_debug_implementations
10+
)]
11+
112
use futures::prelude::*;
213
use http_service::Body;
314
use multipart::server::Multipart;
415
use std::io::Cursor;
516

6-
use crate::{
7-
error::{BoxTryFuture, ResultExt},
8-
Context, Response,
9-
};
17+
use tide_core::{err_fmt, error::ResultExt, internal::BoxTryFuture, Context, Response};
1018

1119
/// An extension trait for `Context`, providing form extraction.
1220
pub trait ContextExt {

tide-headers/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! Crate that provides helpers, and/or middlewares for tide
1+
//! Crate that provides helpers and/or middlewares for Tide
22
//! related to http headers.
3+
34
#![feature(async_await)]
45
#![warn(
56
nonstandard_style,

tide-log/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Crate that provides helpers and/or middlewares for tide
1+
//! Crate that provides helpers and/or middlewares for Tide
22
//! related to logging.
3-
//!
3+
44
#![feature(async_await)]
55
#![warn(
66
nonstandard_style,

tide-querystring/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
authors = [
3+
"Tide Developers"
4+
]
5+
description = "Query string helpers and extensions for Tide"
6+
documentation = "https://docs.rs/tide-querystring"
7+
keywords = ["tide", "web", "async", "helpers", "querystring"]
8+
categories = [
9+
"network-programming",
10+
"web-programming::http-server",
11+
]
12+
edition = "2018"
13+
license = "MIT OR Apache-2.0"
14+
name = "tide-querystring"
15+
readme = "README.md"
16+
repository = "https://github.com/rustasync/tide"
17+
version = "0.1.0"
18+
19+
[dependencies]
20+
tide-core = { path = "../tide-core" }
21+
futures-preview = "0.3.0-alpha.16"
22+
http = "0.1"
23+
log = "0.4.6"
24+
serde = { version = "1.0.91", features = ["derive"] }
25+
serde_urlencoded = "0.5.5"
26+
27+
[dev-dependencies]
28+
tide = { path = "../" }
29+
http-service = "0.2.0"
30+
http-service-mock = "0.2.0"
31+

src/querystring.rs renamed to tide-querystring/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
use crate::{error::Error, Context};
1+
//! Crate that provides helpers and extensions for Tide
2+
//! related to query strings.
3+
4+
#![feature(async_await)]
5+
#![warn(
6+
nonstandard_style,
7+
rust_2018_idioms,
8+
future_incompatible,
9+
missing_debug_implementations
10+
)]
11+
212
use http::StatusCode;
313
use serde::Deserialize;
14+
use tide_core::{error::Error, Context};
415

516
/// An extension trait for `Context`, providing query string deserialization.
617
pub trait ContextExt<'de> {
@@ -11,11 +22,9 @@ impl<'de, State> ContextExt<'de> for Context<State> {
1122
#[inline]
1223
fn url_query<T: Deserialize<'de>>(&'de self) -> Result<T, Error> {
1324
let query = self.uri().query();
14-
1525
if query.is_none() {
1626
return Err(Error::from(StatusCode::BAD_REQUEST));
1727
}
18-
1928
Ok(serde_urlencoded::from_str(query.unwrap())
2029
.map_err(|_| Error::from(StatusCode::BAD_REQUEST))?)
2130
}
@@ -27,20 +36,20 @@ mod tests {
2736
use futures::executor::block_on;
2837
use http_service::Body;
2938
use http_service_mock::make_server;
30-
use serde_derive::Deserialize;
39+
use serde::Deserialize;
3140

3241
#[derive(Deserialize)]
3342
struct Params {
3443
msg: String,
3544
}
3645

37-
async fn handler(cx: crate::Context<()>) -> Result<String, Error> {
46+
async fn handler(cx: tide::Context<()>) -> Result<String, Error> {
3847
let p = cx.url_query::<Params>()?;
3948
Ok(p.msg)
4049
}
4150

42-
fn app() -> crate::App<()> {
43-
let mut app = crate::App::new();
51+
fn app() -> tide::App<()> {
52+
let mut app = tide::App::new();
4453
app.at("/").get(handler);
4554
app
4655
}

tide-slog/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = [
44
]
55
description = "Logging middleware for Tide based on slog"
66
documentation = "https://docs.rs/tide-slog"
7-
keywords = ["tide", "web", "async", "middleware", "logging", "slog"]
7+
keywords = ["tide", "web", "middleware", "logging", "slog"]
88
categories = [
99
"logging",
1010
"network-programming",

tide-slog/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Crate that provides helpers and/or middlewares for Tide
2+
//! related to structured logging with slog.
3+
14
#![feature(async_await)]
25
#![warn(
36
nonstandard_style,

0 commit comments

Comments
 (0)