File tree Expand file tree Collapse file tree 4 files changed +30
-23
lines changed Expand file tree Collapse file tree 4 files changed +30
-23
lines changed Original file line number Diff line number Diff line change @@ -16,16 +16,18 @@ default = []
16
16
hyperium_http = [" http" ]
17
17
18
18
[dependencies ]
19
- async-std = { version = " 1.4.0 " , features = [ " unstable " ] }
19
+ anyhow = " 1.0.26 "
20
20
cookie = " 0.12.0"
21
21
infer = " 0.1.2"
22
+ omnom = " 2.1.1"
22
23
pin-project-lite = " 0.1.0"
23
24
url = " 2.1.0"
24
- omnom = " 2.1.1"
25
+
26
+ # Note(yoshuawuyts): used for async_std's `channel` only; use "core" once possible.
27
+ async-std = { version = " 1.4.0" , features = [" unstable" ] }
25
28
26
29
# features: hyperium/http
27
30
http = { version = " 0.2.0" , optional = true }
28
- anyhow = " 1.0.26"
29
31
30
32
[dev-dependencies ]
31
33
http = " 0.2.0"
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ pin_project_lite::pin_project! {
35
35
receiver: sync:: Receiver <crate :: Result <Trailers >>,
36
36
#[ pin]
37
37
body: Body ,
38
- local_state : TypeMap ,
38
+ local : TypeMap ,
39
39
}
40
40
}
41
41
@@ -51,7 +51,7 @@ impl Request {
51
51
body : Body :: empty ( ) ,
52
52
sender : Some ( sender) ,
53
53
receiver,
54
- local_state : TypeMap :: new ( ) ,
54
+ local : TypeMap :: new ( ) ,
55
55
}
56
56
}
57
57
@@ -427,8 +427,8 @@ impl Request {
427
427
}
428
428
429
429
/// Returns a reference to the existing local state.
430
- pub fn local_state ( & self ) -> & TypeMap {
431
- & self . local_state
430
+ pub fn local ( & self ) -> & TypeMap {
431
+ & self . local
432
432
}
433
433
434
434
/// Returns a mutuable reference to the existing local state.
@@ -442,13 +442,13 @@ impl Request {
442
442
/// use http_types::{Url, Method, Request, Version};
443
443
///
444
444
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
445
- /// req.local_state_mut ().insert("hello from the extension");
446
- /// assert_eq!(req.local_state ().get(), Some(&"hello from the extension"));
445
+ /// req.local_mut ().insert("hello from the extension");
446
+ /// assert_eq!(req.local ().get(), Some(&"hello from the extension"));
447
447
/// #
448
448
/// # Ok(()) }
449
449
/// ```
450
- pub fn local_state_mut ( & mut self ) -> & mut TypeMap {
451
- & mut self . local_state
450
+ pub fn local_mut ( & mut self ) -> & mut TypeMap {
451
+ & mut self . local
452
452
}
453
453
}
454
454
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ pin_project_lite::pin_project! {
37
37
receiver: sync:: Receiver <crate :: Result <Trailers >>,
38
38
#[ pin]
39
39
body: Body ,
40
- local_state : TypeMap ,
40
+ local : TypeMap ,
41
41
}
42
42
}
43
43
@@ -52,7 +52,7 @@ impl Response {
52
52
body : Body :: empty ( ) ,
53
53
sender : Some ( sender) ,
54
54
receiver,
55
- local_state : TypeMap :: new ( ) ,
55
+ local : TypeMap :: new ( ) ,
56
56
}
57
57
}
58
58
@@ -392,9 +392,9 @@ impl Response {
392
392
self . headers . values ( )
393
393
}
394
394
395
- /// Returns a reference to the existing local_state .
396
- pub fn local_state ( & self ) -> & TypeMap {
397
- & self . local_state
395
+ /// Returns a reference to the existing local .
396
+ pub fn local ( & self ) -> & TypeMap {
397
+ & self . local
398
398
}
399
399
400
400
/// Returns a mutuable reference to the existing local state.
@@ -408,13 +408,13 @@ impl Response {
408
408
/// use http_types::{StatusCode, Response, Version};
409
409
///
410
410
/// let mut res = Response::new(StatusCode::Ok);
411
- /// res.local_state_mut ().insert("hello from the extension");
412
- /// assert_eq!(res.local_state ().get(), Some(&"hello from the extension"));
411
+ /// res.local_mut ().insert("hello from the extension");
412
+ /// assert_eq!(res.local ().get(), Some(&"hello from the extension"));
413
413
/// #
414
414
/// # Ok(()) }
415
415
/// ```
416
- pub fn local_state_mut ( & mut self ) -> & mut TypeMap {
417
- & mut self . local_state
416
+ pub fn local_mut ( & mut self ) -> & mut TypeMap {
417
+ & mut self . local
418
418
}
419
419
}
420
420
Original file line number Diff line number Diff line change @@ -7,8 +7,13 @@ use std::collections::HashMap;
7
7
use std:: fmt;
8
8
use std:: hash:: { BuildHasherDefault , Hasher } ;
9
9
10
- /// Map type that allows storing any `Sync + Send + 'static` type as local state
11
- /// on a `Request` or `Response`.
10
+ /// Store and retrieve values by `TypeId`.
11
+ ///
12
+ /// Map type that allows storing any `Sync + Send + 'static` type. Instances can
13
+ /// be retrieved from [`Request::local`](struct.Request.html#method.local) +
14
+ /// [`Response::local`](struct.Response.html#method.local) and
15
+ /// [`Request::local_mut`](struct.Request.html#method.local_mut) +
16
+ /// [`Response::local_mut`](struct.Response.html#method.local_mut).
12
17
#[ derive( Default ) ]
13
18
pub struct TypeMap {
14
19
map : Option < HashMap < TypeId , Box < dyn Any + Send + Sync > , BuildHasherDefault < IdHasher > > > ,
@@ -17,7 +22,7 @@ pub struct TypeMap {
17
22
impl TypeMap {
18
23
/// Create an empty `TypeMap`.
19
24
#[ inline]
20
- pub fn new ( ) -> Self {
25
+ pub ( crate ) fn new ( ) -> Self {
21
26
Self { map : None }
22
27
}
23
28
You can’t perform that action at this time.
0 commit comments