File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ extern crate semver;
3
3
use std:: collections:: HashMap ;
4
4
use std:: io:: net:: ip:: IpAddr ;
5
5
use std:: hash:: Hash ;
6
- use std:: any:: Any ;
7
6
use std:: fmt:: Show ;
8
7
8
+ pub use self :: typemap:: TypeMap ;
9
+ mod typemap;
10
+
9
11
#[ deriving( PartialEq , Show , Clone ) ]
10
12
pub enum Scheme {
11
13
Http ,
@@ -38,7 +40,7 @@ pub enum Method {
38
40
}
39
41
40
42
/// A Dictionary for extensions provided by the server or middleware
41
- pub type Extensions = HashMap < & ' static str , Box < Any > > ;
43
+ pub type Extensions = TypeMap ;
42
44
43
45
pub trait Request {
44
46
/// The version of HTTP being used
Original file line number Diff line number Diff line change
1
+ use std:: any:: { Any , AnyMutRefExt , AnyRefExt } ;
2
+ use std:: intrinsics:: TypeId ;
3
+ use std:: collections:: HashMap ;
4
+
5
+ pub struct TypeMap {
6
+ data : HashMap < TypeId , Box < Any > >
7
+ }
8
+
9
+ impl TypeMap {
10
+ pub fn find < T : ' static > ( & self ) -> Option < & T > {
11
+ self . data . find ( & TypeId :: of :: < T > ( ) ) . and_then ( |a| a. downcast_ref ( ) )
12
+ }
13
+
14
+ pub fn find_mut < T : ' static > ( & mut self ) -> Option < & mut T > {
15
+ self . data . find_mut ( & TypeId :: of :: < T > ( ) ) . and_then ( |a| a. downcast_mut ( ) )
16
+ }
17
+
18
+ pub fn insert < T : ' static > ( & mut self , val : T ) -> bool {
19
+ self . data . insert ( TypeId :: of :: < T > ( ) , box val as Box < Any > )
20
+ }
21
+
22
+ pub fn remove < T : ' static > ( & mut self ) -> bool {
23
+ self . data . remove ( & TypeId :: of :: < T > ( ) )
24
+ }
25
+
26
+ pub fn contains < T : ' static > ( & mut self ) -> bool {
27
+ self . data . contains_key ( & TypeId :: of :: < T > ( ) )
28
+ }
29
+ }
30
+
You can’t perform that action at this time.
0 commit comments