1
- use std:: collections:: hash_map;
2
- use std:: collections:: HashMap ;
3
- use std:: hash:: Hash ;
4
-
5
1
use crate :: reflect:: reflect_eq:: ReflectEq ;
6
2
use crate :: reflect:: reflect_eq:: ReflectEqMode ;
7
- use crate :: reflect:: runtime_types:: RuntimeTypeHashable ;
8
- use crate :: reflect:: ProtobufValue ;
9
3
use crate :: reflect:: ReflectValueBox ;
10
4
use crate :: reflect:: ReflectValueRef ;
11
5
use crate :: reflect:: RuntimeTypeBox ;
12
6
7
+ mod generated;
8
+
13
9
/// Implemented for `HashMap` with appropriate keys and values
14
10
pub ( crate ) trait ReflectMap : Send + Sync + ' static {
15
11
fn reflect_iter ( & self ) -> ReflectMapIter ;
@@ -29,78 +25,12 @@ pub(crate) trait ReflectMap: Send + Sync + 'static {
29
25
fn value_type ( & self ) -> RuntimeTypeBox ;
30
26
}
31
27
32
- impl < K , V > ReflectMap for HashMap < K , V >
33
- where
34
- K : ProtobufValue + Eq + Hash ,
35
- V : ProtobufValue ,
36
- K :: RuntimeType : RuntimeTypeHashable ,
37
- {
38
- fn reflect_iter < ' a > ( & ' a self ) -> ReflectMapIter < ' a > {
39
- ReflectMapIter {
40
- imp : Box :: new ( ReflectMapIterImpl :: < ' a , K , V > { iter : self . iter ( ) } ) ,
41
- }
42
- }
43
-
44
- fn len ( & self ) -> usize {
45
- HashMap :: len ( self )
46
- }
47
-
48
- fn is_empty ( & self ) -> bool {
49
- self . is_empty ( )
50
- }
51
-
52
- fn get < ' a > ( & ' a self , key : ReflectValueRef ) -> Option < ReflectValueRef < ' a > > {
53
- <K :: RuntimeType as RuntimeTypeHashable >:: hash_map_get ( self , key) . map ( V :: as_ref)
54
- }
55
-
56
- fn insert ( & mut self , key : ReflectValueBox , value : ReflectValueBox ) {
57
- let key: K = key. downcast ( ) . expect ( "wrong key type" ) ;
58
- let value: V = value. downcast ( ) . expect ( "wrong value type" ) ;
59
- self . insert ( key, value) ;
60
- }
61
-
62
- fn clear ( & mut self ) {
63
- self . clear ( ) ;
64
- }
65
-
66
- fn key_type ( & self ) -> RuntimeTypeBox {
67
- K :: runtime_type_box ( )
68
- }
69
-
70
- fn value_type ( & self ) -> RuntimeTypeBox {
71
- V :: runtime_type_box ( )
72
- }
73
- }
74
-
75
28
trait ReflectMapIterTrait < ' a > {
76
29
fn next ( & mut self ) -> Option < ( ReflectValueRef < ' a > , ReflectValueRef < ' a > ) > ;
77
30
fn key_type ( & self ) -> RuntimeTypeBox ;
78
31
fn value_type ( & self ) -> RuntimeTypeBox ;
79
32
}
80
33
81
- struct ReflectMapIterImpl < ' a , K : Eq + Hash + ' static , V : ' static > {
82
- iter : hash_map:: Iter < ' a , K , V > ,
83
- }
84
-
85
- impl < ' a , K : ProtobufValue + Eq + Hash , V : ProtobufValue > ReflectMapIterTrait < ' a >
86
- for ReflectMapIterImpl < ' a , K , V >
87
- {
88
- fn next ( & mut self ) -> Option < ( ReflectValueRef < ' a > , ReflectValueRef < ' a > ) > {
89
- match self . iter . next ( ) {
90
- Some ( ( k, v) ) => Some ( ( K :: as_ref ( k) , V :: as_ref ( v) ) ) ,
91
- None => None ,
92
- }
93
- }
94
-
95
- fn key_type ( & self ) -> RuntimeTypeBox {
96
- K :: runtime_type_box ( )
97
- }
98
-
99
- fn value_type ( & self ) -> RuntimeTypeBox {
100
- V :: runtime_type_box ( )
101
- }
102
- }
103
-
104
34
pub struct ReflectMapIter < ' a > {
105
35
imp : Box < dyn ReflectMapIterTrait < ' a > + ' a > ,
106
36
}
0 commit comments