Skip to content

Commit 4c1f629

Browse files
authored
Merge pull request #455 from http-rs/export-some-http-types
export http_types::{Body, StatusCode}
2 parents df00291 + 0608b0e commit 4c1f629

File tree

14 files changed

+38
-49
lines changed

14 files changed

+38
-49
lines changed

backup/examples/staticfile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use http::{
55
header::{self, HeaderMap},
66
StatusCode,
77
};
8-
use http_service::Body;
9-
use tide::{Request, Response, Result, Server};
8+
use tide::{Body, Request, Response, Result, Server};
109

1110
use std::path::{Component, Path, PathBuf};
1211
use std::{fs, io};

examples/chunked.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use async_std::fs;
22
use async_std::io::BufReader;
33
use async_std::task;
4-
use http_types::StatusCode;
5-
use tide::Response;
4+
use tide::{Response, StatusCode};
65

76
fn main() -> Result<(), std::io::Error> {
87
task::block_on(async {

examples/cookies.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use async_std::task;
22
use cookie::Cookie;
3-
use http_types::StatusCode;
4-
use tide::{Request, Response};
3+
use tide::{Request, Response, StatusCode};
54

65
/// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter.
76
///

examples/graphql.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use async_std::task;
2-
use http_types::StatusCode;
32
use juniper::RootNode;
43
use std::sync::RwLock;
5-
use tide::{redirect, Request, Response, Server};
4+
use tide::{redirect, Request, Response, Server, StatusCode};
65

76
#[derive(Clone)]
87
struct User {

examples/json.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use async_std::io;
22
use async_std::task;
3-
use http_types::StatusCode;
43
use serde::{Deserialize, Serialize};
4+
use tide::{Request, Response, StatusCode};
55

66
#[derive(Deserialize, Serialize)]
77
struct Cat {
@@ -12,17 +12,16 @@ fn main() -> io::Result<()> {
1212
task::block_on(async {
1313
let mut app = tide::new();
1414

15-
app.at("/submit")
16-
.post(|mut req: tide::Request<()>| async move {
17-
let cat: Cat = req.body_json().await?;
18-
println!("cat name: {}", cat.name);
15+
app.at("/submit").post(|mut req: Request<()>| async move {
16+
let cat: Cat = req.body_json().await?;
17+
println!("cat name: {}", cat.name);
1918

20-
let cat = Cat {
21-
name: "chashu".into(),
22-
};
19+
let cat = Cat {
20+
name: "chashu".into(),
21+
};
2322

24-
Ok(tide::Response::new(StatusCode::Ok).body_json(&cat)?)
25-
});
23+
Ok(Response::new(StatusCode::Ok).body_json(&cat)?)
24+
});
2625

2726
app.listen("127.0.0.1:8080").await?;
2827
Ok(())

src/cookies/middleware.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use std::sync::{Arc, RwLock};
1313
/// # Examples
1414
///
1515
/// ```
16+
/// # use tide::{Request, Response, StatusCode};
1617
/// let mut app = tide::Server::new();
17-
/// app.at("/get").get(|cx: tide::Request<()>| async move { Ok(cx.cookie("testCookie").unwrap().value().to_string()) });
18+
/// app.at("/get").get(|cx: Request<()>| async move { Ok(cx.cookie("testCookie").unwrap().value().to_string()) });
1819
/// app.at("/set").get(|_| async {
19-
/// let mut res = tide::Response::new(http_types::StatusCode::Ok);
20+
/// let mut res = Response::new(StatusCode::Ok);
2021
/// res.set_cookie(cookie::Cookie::new("testCookie", "NewCookieValue"));
2122
/// Ok(res)
2223
/// });

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub use request::Request;
204204
pub mod sse;
205205

206206
#[doc(inline)]
207-
pub use http_types::{Error, Result, Status};
207+
pub use http_types::{Body, Error, Result, Status, StatusCode};
208208

209209
#[doc(inline)]
210210
pub use middleware::{Middleware, Next};

src/response/into_response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::StatusCode;
12
use crate::{Request, Response};
23
use async_std::io::BufReader;
3-
use http_types::StatusCode;
44

55
/// Conversion into a `Response`.
66
pub trait IntoResponse: Send + Sized {
@@ -14,7 +14,7 @@ pub trait IntoResponse: Send + Sized {
1414
/// let resp = "Hello, 404!".with_status(http_types::StatusCode::NotFound).into_response();
1515
/// assert_eq!(resp.status(), http_types::StatusCode::NotFound);
1616
/// ```
17-
fn with_status(self, status: http_types::StatusCode) -> WithStatus<Self> {
17+
fn with_status(self, status: StatusCode) -> WithStatus<Self> {
1818
WithStatus {
1919
inner: self,
2020
status,

src/response/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Response {
4343
where
4444
R: BufRead + Unpin + Send + Sync + 'static,
4545
{
46-
let status = http_types::StatusCode::try_from(status).expect("invalid status code");
46+
let status = crate::StatusCode::try_from(status).expect("invalid status code");
4747
let mut res = http_types::Response::new(status);
4848
res.set_body(Body::from_reader(reader, None));
4949

@@ -59,15 +59,15 @@ impl Response {
5959
/// # Example
6060
///
6161
/// ```
62-
/// # use tide::{Response, Request};
62+
/// # use tide::{Response, Request, StatusCode};
6363
/// # fn canonicalize(uri: &url::Url) -> Option<&url::Url> { None }
6464
/// # #[allow(dead_code)]
6565
/// async fn route_handler(request: Request<()>) -> tide::Result<Response> {
6666
/// if let Some(canonical_redirect) = canonicalize(request.uri()) {
6767
/// Ok(Response::redirect_permanent(canonical_redirect))
6868
/// } else {
6969
/// //...
70-
/// # Ok(Response::new(http_types::StatusCode::Ok)) // ...
70+
/// # Ok(Response::new(StatusCode::Ok)) // ...
7171
/// }
7272
/// }
7373
/// ```
@@ -82,15 +82,15 @@ impl Response {
8282
/// # Example
8383
///
8484
/// ```
85-
/// # use tide::{Response, Request};
85+
/// # use tide::{Response, Request, StatusCode};
8686
/// # fn special_sale_today() -> Option<String> { None }
8787
/// # #[allow(dead_code)]
8888
/// async fn route_handler(request: Request<()>) -> tide::Result<Response> {
8989
/// if let Some(sale_url) = special_sale_today() {
9090
/// Ok(Response::redirect_temporary(sale_url))
9191
/// } else {
9292
/// //...
93-
/// # Ok(Response::new(http_types::StatusCode::Ok)) //...
93+
/// # Ok(Response::new(StatusCode::Ok)) //...
9494
/// }
9595
/// }
9696
/// ```
@@ -100,12 +100,12 @@ impl Response {
100100
}
101101

102102
/// Returns the statuscode.
103-
pub fn status(&self) -> http_types::StatusCode {
103+
pub fn status(&self) -> crate::StatusCode {
104104
self.res.status()
105105
}
106106

107107
/// Set the statuscode.
108-
pub fn set_status(mut self, status: http_types::StatusCode) -> Self {
108+
pub fn set_status(mut self, status: crate::StatusCode) -> Self {
109109
self.res.set_status(status);
110110
self
111111
}

src/router.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ impl<State: 'static> Router<State> {
8888
}
8989

9090
fn not_found_endpoint<State>(_cx: Request<State>) -> BoxFuture<'static, Result<Response>> {
91-
Box::pin(async move { Ok(Response::new(http_types::StatusCode::NotFound.into())) })
91+
Box::pin(async move { Ok(Response::new(crate::StatusCode::NotFound.into())) })
9292
}
9393

9494
fn method_not_allowed<State>(_cx: Request<State>) -> BoxFuture<'static, Result<Response>> {
95-
Box::pin(async move {
96-
Ok(Response::new(
97-
http_types::StatusCode::MethodNotAllowed.into(),
98-
))
99-
})
95+
Box::pin(async move { Ok(Response::new(crate::StatusCode::MethodNotAllowed.into())) })
10096
}

0 commit comments

Comments
 (0)