Skip to content

Commit 792922d

Browse files
committed
Split state off from Request
1 parent 0a1327a commit 792922d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+227
-236
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn main() -> tide::Result<()> {
8080
Ok(())
8181
}
8282

83-
async fn order_shoes(mut req: Request<()>) -> tide::Result {
83+
async fn order_shoes(mut req: Request, _state: ()) -> tide::Result {
8484
let Animal { name, legs } = req.body_json().await?;
8585
Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
8686
}

examples/catflap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ async fn main() -> Result<(), std::io::Error> {
44
use std::{env, net::TcpListener, os::unix::io::FromRawFd};
55
tide::log::start();
66
let mut app = tide::new();
7-
app.at("/").get(|_| async { Ok(CHANGE_THIS_TEXT) });
7+
app.at("/").get(|_, _| async { Ok(CHANGE_THIS_TEXT) });
88

99
const CHANGE_THIS_TEXT: &str = "hello world!";
1010

examples/chunked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tide::Body;
44
async fn main() -> Result<(), std::io::Error> {
55
tide::log::start();
66
let mut app = tide::new();
7-
app.at("/").get(|_| async {
7+
app.at("/").get(|_, _| async {
88
// File sends are chunked by default.
99
Ok(Body::from_file(file!()).await?)
1010
});

examples/concurrent_listeners.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ async fn main() -> Result<(), std::io::Error> {
55
tide::log::start();
66
let mut app = tide::new();
77

8-
app.at("/").get(|request: Request<_>| async move {
8+
app.at("/").get(|req: Request, _| async move {
99
Ok(format!(
1010
"Hi! You reached this app through: {}",
11-
request.local_addr().unwrap_or("an unknown port")
11+
req.local_addr().unwrap_or("an unknown port")
1212
))
1313
});
1414

examples/cookies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ use tide::{Request, Response, StatusCode};
33

44
/// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter.
55
///
6-
async fn retrieve_cookie(req: Request<()>) -> tide::Result<String> {
6+
async fn retrieve_cookie(req: Request, _state: ()) -> tide::Result<String> {
77
Ok(format!("hello cookies: {:?}", req.cookie("hello").unwrap()))
88
}
99

10-
async fn insert_cookie(_req: Request<()>) -> tide::Result {
10+
async fn insert_cookie(_req: Request, _state: ()) -> tide::Result {
1111
let mut res = Response::new(StatusCode::Ok);
1212
res.insert_cookie(Cookie::new("hello", "world"));
1313
Ok(res)
1414
}
1515

16-
async fn remove_cookie(_req: Request<()>) -> tide::Result {
16+
async fn remove_cookie(_req: Request, _state: ()) -> tide::Result {
1717
let mut res = Response::new(StatusCode::Ok);
1818
res.remove_cookie(Cookie::named("hello"));
1919
Ok(res)

examples/error_handling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::ErrorKind;
22

33
use tide::utils::After;
4-
use tide::{Body, Request, Response, Result, StatusCode};
4+
use tide::{Body, Response, Result, StatusCode};
55

66
#[async_std::main]
77
async fn main() -> Result<()> {
@@ -22,7 +22,7 @@ async fn main() -> Result<()> {
2222
}));
2323

2424
app.at("/")
25-
.get(|_req: Request<_>| async { Ok(Body::from_file("./does-not-exist").await?) });
25+
.get(|_, _| async { Ok(Body::from_file("./does-not-exist").await?) });
2626

2727
app.listen("127.0.0.1:8080").await?;
2828

examples/fib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn fib(n: usize) -> usize {
88
}
99
}
1010

11-
async fn fibsum(req: Request<()>) -> tide::Result<String> {
11+
async fn fibsum(req: Request, _state: ()) -> tide::Result<String> {
1212
use std::time::Instant;
1313
let n: usize = req.param("n")?.parse().unwrap_or(0);
1414
// Start a stopwatch

examples/graphql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ lazy_static! {
7474
static ref SCHEMA: Schema = Schema::new(QueryRoot {}, MutationRoot {});
7575
}
7676

77-
async fn handle_graphql(mut request: Request<State>) -> tide::Result {
77+
async fn handle_graphql(mut request: Request, state: State) -> tide::Result {
7878
let query: GraphQLRequest = request.body_json().await?;
79-
let response = query.execute(&SCHEMA, request.state());
79+
let response = query.execute(&SCHEMA, &state);
8080
let status = if response.is_ok() {
8181
StatusCode::Ok
8282
} else {
@@ -88,7 +88,7 @@ async fn handle_graphql(mut request: Request<State>) -> tide::Result {
8888
.build())
8989
}
9090

91-
async fn handle_graphiql(_: Request<State>) -> tide::Result<impl Into<Response>> {
91+
async fn handle_graphiql(_: Request, _state: State) -> tide::Result<impl Into<Response>> {
9292
Ok(Response::builder(200)
9393
.body(graphiql::graphiql_source("/graphql"))
9494
.content_type(mime::HTML))

examples/hello.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
async fn main() -> Result<(), std::io::Error> {
33
tide::log::start();
44
let mut app = tide::new();
5-
app.at("/").get(|_| async { Ok("Hello, world!") });
5+
app.at("/").get(|_, _| async { Ok("Hello, world!") });
66
app.listen("127.0.0.1:8080").await?;
77
Ok(())
88
}

examples/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async fn main() -> tide::Result<()> {
1212
tide::log::start();
1313
let mut app = tide::new();
1414

15-
app.at("/submit").post(|mut req: Request<()>| async move {
15+
app.at("/submit").post(|mut req: Request, _| async move {
1616
let cat: Cat = req.body_json().await?;
1717
println!("cat name: {}", cat.name);
1818

@@ -23,7 +23,7 @@ async fn main() -> tide::Result<()> {
2323
Ok(Body::from_json(&cat)?)
2424
});
2525

26-
app.at("/animals").get(|_| async {
26+
app.at("/animals").get(|_, _| async {
2727
Ok(json!({
2828
"meta": { "count": 2 },
2929
"animals": [

0 commit comments

Comments
 (0)