Skip to content

Commit 0c13fc4

Browse files
authored
conduit: Use http::Extensions instead of custom TypeMap (#57)
1 parent ad5d88d commit 0c13fc4

File tree

4 files changed

+6
-77
lines changed

4 files changed

+6
-77
lines changed

conduit-middleware/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ mod tests {
224224
}
225225
}
226226

227-
fn get_extension<T: Any>(req: &dyn RequestExt) -> &T {
228-
req.extensions().find::<T>().unwrap()
227+
fn get_extension<T: Any + Send + Sync>(req: &dyn RequestExt) -> &T {
228+
req.extensions().get::<T>().unwrap()
229229
}
230230

231231
fn response(string: String) -> Response<Body> {

conduit-router/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub trait RequestParams<'a> {
143143

144144
impl<'a> RequestParams<'a> for &'a (dyn RequestExt + 'a) {
145145
fn params(self) -> &'a Params {
146-
self.extensions().find::<Params>().expect("Missing params")
146+
self.extensions().get::<Params>().expect("Missing params")
147147
}
148148
}
149149

@@ -235,7 +235,7 @@ mod tests {
235235
req.params().find("id").unwrap_or("").to_string(),
236236
format!("{:?}", req.method()),
237237
req.extensions()
238-
.find::<RoutePattern>()
238+
.get::<RoutePattern>()
239239
.unwrap()
240240
.pattern()
241241
.to_string(),

conduit/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::time::{Duration, Instant};
88

99
pub use http::{header, HeaderMap, Method, Request, Response, StatusCode, Version};
1010

11-
mod typemap;
12-
1311
pub type ResponseResult<Error> = Result<Response<Body>, Error>;
1412
pub type HttpResult = ResponseResult<http::Error>;
1513

@@ -83,7 +81,7 @@ pub enum Host<'a> {
8381
}
8482

8583
/// A Dictionary for extensions provided by the server or middleware
86-
pub type Extensions = typemap::TypeMap;
84+
pub type Extensions = http::Extensions;
8785

8886
pub trait RequestExt {
8987
/// The elapsed time since the start of the request (headers received)
@@ -93,11 +91,7 @@ pub trait RequestExt {
9391
/// This method may panic if the server does not add `StartInstant` to the
9492
/// request extensions, or if it has been removed by the application.
9593
fn elapsed(&self) -> Duration {
96-
self.extensions()
97-
.find::<StartInstant>()
98-
.unwrap()
99-
.0
100-
.elapsed()
94+
self.extensions().get::<StartInstant>().unwrap().0.elapsed()
10195
}
10296

10397
/// The version of HTTP being used

conduit/src/typemap.rs

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

0 commit comments

Comments
 (0)