Skip to content

Commit 3294cc6

Browse files
committed
Uncouple endpoint construction from routing
The result looks more clunky for binding it to a route but at least the concerns are separate more strictly. This also removes the need for duplicating the router utilities for methods.
1 parent cd48e8f commit 3294cc6

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

examples/seeded_extractor.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(async_await, futures_api)]
22

3+
use tide::Seeded;
34
use tide::head::{NamedHeader, Header, SegmentName, Named};
45
use http::header::{HeaderName, HeaderValue};
56

@@ -13,7 +14,7 @@ async fn display_number(nr: Named<i32>) -> String {
1314

1415
fn main() {
1516
let mut app = tide::App::new(());
16-
app.at("/").get_with(display_header, NamedHeader(HeaderName::from_static("user-agent")));
17-
app.at("/numbered/{num}").get_with(display_number, SegmentName("num".into()));
17+
app.at("/").get(Seeded(display_header, NamedHeader(HeaderName::from_static("user-agent"))));
18+
app.at("/numbered/{num}").get(Seeded(display_number, SegmentName("num".into())));
1819
app.serve();
1920
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use crate::{
2929
app::{App, AppData, Server},
3030
configuration::ExtractConfiguration,
3131
cookies::Cookies,
32-
endpoint::Endpoint,
32+
endpoint::{Endpoint, Seeded},
3333
extract::{Extract, ExtractSeed},
3434
middleware::Middleware,
3535
request::{Compute, Computed, Request},

src/router.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
use crate::{
77
configuration::Store,
8-
endpoint::{BoxedEndpoint, Endpoint, Seeded},
8+
endpoint::{BoxedEndpoint, Endpoint},
99
Middleware,
1010
};
1111
use path_table::{PathTable, RouteMatch};
@@ -279,12 +279,6 @@ impl<'a, Data> Resource<'a, Data> {
279279
self.method(http::Method::GET, ep)
280280
}
281281

282-
pub fn get_with<T, S, U>(&mut self, ep: T, seed: S) -> &mut EndpointData<Data>
283-
where Seeded<T, S>: Endpoint<Data, U>
284-
{
285-
self.method(http::Method::GET, Seeded(ep, seed))
286-
}
287-
288282
/// Add an endpoint for `HEAD` requests
289283
pub fn head<T: Endpoint<Data, U>, U>(&mut self, ep: T) -> &mut EndpointData<Data> {
290284
self.method(http::Method::HEAD, ep)

0 commit comments

Comments
 (0)