@@ -39,6 +39,10 @@ pub static ARRAY: &str = "Array";
39
39
pub static I32 : & str = "Int32" ;
40
40
pub static I64 : & str = "Long" ;
41
41
pub static NULL : & str = "Null" ;
42
+ pub static DB_POINTER : & str = "DbPointer" ;
43
+ pub static MAX_KEY : & str = "MaxKey" ;
44
+ pub static MIN_KEY : & str = "MinKey" ;
45
+ pub static UNDEFINED : & str = "Undefined" ;
42
46
43
47
impl FieldType {
44
48
pub fn new < T , U > ( path : T , bson_type : U ) -> Self
@@ -157,19 +161,20 @@ impl FieldType {
157
161
158
162
pub fn get_value ( value : & Bson ) -> Option < ValueType > {
159
163
match value {
160
- Bson :: RegExp ( val, _)
161
- | Bson :: JavaScriptCode ( val)
162
- | Bson :: JavaScriptCodeWithScope ( val, _)
164
+ Bson :: JavaScriptCode ( val)
163
165
| Bson :: Symbol ( val) => Some ( ValueType :: Str ( val. to_string ( ) ) ) ,
164
- Bson :: I64 ( num) | Bson :: TimeStamp ( num) => Some ( ValueType :: I64 ( * num) ) ,
165
- Bson :: FloatingPoint ( num) => Some ( ValueType :: FloatingPoint ( * num) ) ,
166
- Bson :: UtcDatetime ( date) => Some ( ValueType :: Str ( date. clone ( ) . to_string ( ) ) ) ,
166
+ Bson :: JavaScriptCodeWithScope ( val) => Some ( ValueType :: Str ( val. to_string ( ) ) ) ,
167
+ Bson :: Int32 ( num) => Some ( ValueType :: I32 ( * num) ) ,
168
+ Bson :: Int64 ( num) => Some ( ValueType :: I64 ( * num) ) ,
169
+ Bson :: Timestamp ( num) => Some ( ValueType :: I32 ( num. time as i32 ) ) ,
170
+ Bson :: Double ( num) => Some ( ValueType :: FloatingPoint ( * num) ) ,
171
+ Bson :: DateTime ( date) => Some ( ValueType :: Str ( date. clone ( ) . to_string ( ) ) ) ,
167
172
Bson :: Decimal128 ( d128) => Some ( ValueType :: Decimal128 ( d128. to_string ( ) ) ) ,
168
173
Bson :: Boolean ( boolean) => Some ( ValueType :: Boolean ( * boolean) ) ,
174
+ Bson :: RegularExpression ( val) => Some ( ValueType :: Str ( val. to_string ( ) ) ) ,
169
175
Bson :: String ( string) => Some ( ValueType :: Str ( string. to_string ( ) ) ) ,
170
- Bson :: Binary ( _ , vec) => Some ( ValueType :: Binary ( vec. clone ( ) ) ) ,
176
+ Bson :: Binary ( vec) => Some ( ValueType :: Binary ( vec. bytes . clone ( ) ) ) ,
171
177
Bson :: ObjectId ( id) => Some ( ValueType :: Str ( id. to_string ( ) ) ) ,
172
- Bson :: I32 ( num) => Some ( ValueType :: I32 ( * num) ) ,
173
178
Bson :: Null => Some ( ValueType :: Null ( "Null" . to_string ( ) ) ) ,
174
179
// Array and Document get handeled separately
175
180
_ => None ,
@@ -196,25 +201,29 @@ impl FieldType {
196
201
197
202
pub fn get_type ( value : & Bson ) -> String {
198
203
match value {
199
- Bson :: JavaScriptCodeWithScope ( _, _ ) => {
204
+ Bson :: JavaScriptCodeWithScope ( _) => {
200
205
JAVASCRIPT_CODE_WITH_SCOPE . to_string ( )
201
206
}
202
207
Bson :: JavaScriptCode ( _) => JAVASCRIPT_CODE . to_string ( ) ,
203
- Bson :: FloatingPoint ( _) => FLOATING_POINT . to_string ( ) ,
204
- Bson :: UtcDatetime ( _) => UTCDATE_TIME . to_string ( ) ,
208
+ Bson :: Double ( _) => FLOATING_POINT . to_string ( ) ,
209
+ Bson :: DateTime ( _) => UTCDATE_TIME . to_string ( ) ,
205
210
Bson :: Decimal128 ( _) => DECIMAL_128 . to_string ( ) ,
206
- Bson :: TimeStamp ( _) => TIMESTAMP . to_string ( ) ,
207
- Bson :: Binary ( _, _ ) => BINARY . to_string ( ) ,
208
- Bson :: RegExp ( _ , _) => REGEXP . to_string ( ) ,
211
+ Bson :: Timestamp ( _) => TIMESTAMP . to_string ( ) ,
212
+ Bson :: Binary ( _) => BINARY . to_string ( ) ,
213
+ Bson :: RegularExpression ( _) => REGEXP . to_string ( ) ,
209
214
Bson :: Document ( _) => DOCUMENT . to_string ( ) ,
210
215
Bson :: ObjectId ( _) => OBJECTID . to_string ( ) ,
211
216
Bson :: Boolean ( _) => BOOLEAN . to_string ( ) ,
212
217
Bson :: Symbol ( _) => SYMBOL . to_string ( ) ,
213
218
Bson :: String ( _) => STRING . to_string ( ) ,
214
219
Bson :: Array ( _) => ARRAY . to_string ( ) ,
215
- Bson :: I32 ( _) => I32 . to_string ( ) ,
216
- Bson :: I64 ( _) => I64 . to_string ( ) ,
220
+ Bson :: Int32 ( _) => I32 . to_string ( ) ,
221
+ Bson :: Int64 ( _) => I64 . to_string ( ) ,
217
222
Bson :: Null => NULL . to_string ( ) ,
223
+ Bson :: DbPointer ( _) => DB_POINTER . to_string ( ) ,
224
+ Bson :: MaxKey => MAX_KEY . to_string ( ) ,
225
+ Bson :: MinKey => MIN_KEY . to_string ( ) ,
226
+ Bson :: Undefined => UNDEFINED . to_string ( ) ,
218
227
}
219
228
}
220
229
@@ -286,21 +295,21 @@ mod tests {
286
295
287
296
#[ test]
288
297
fn it_gets_value_i32 ( ) {
289
- let bson_value = Bson :: I32 ( 1234 ) ;
298
+ let bson_value = Bson :: Int32 ( 1234 ) ;
290
299
let value = FieldType :: get_value ( & bson_value) ;
291
300
assert_eq ! ( value, Some ( ValueType :: I32 ( 1234 ) ) ) ;
292
301
}
293
302
294
303
#[ test]
295
304
fn it_gets_value_i64 ( ) {
296
- let bson_value = Bson :: I64 ( 1234 ) ;
305
+ let bson_value = Bson :: Int64 ( 1234 ) ;
297
306
let value = FieldType :: get_value ( & bson_value) ;
298
307
assert_eq ! ( value, Some ( ValueType :: I64 ( 1234 ) ) ) ;
299
308
}
300
309
301
310
#[ test]
302
311
fn it_gets_value_floating_point ( ) {
303
- let bson_value = Bson :: FloatingPoint ( 1.2 ) ;
312
+ let bson_value = Bson :: Double ( 1.2 ) ;
304
313
let value = FieldType :: get_value ( & bson_value) ;
305
314
assert_eq ! ( value, Some ( ValueType :: FloatingPoint ( 1.2 ) ) ) ;
306
315
}
@@ -450,7 +459,7 @@ mod tests {
450
459
451
460
#[ test]
452
461
fn it_updates_value_some ( ) {
453
- let bson_value = Bson :: I32 ( 1234 ) ;
462
+ let bson_value = Bson :: Int32 ( 1234 ) ;
454
463
let mut field_type =
455
464
FieldType :: new ( "address" , "Oranienstr. 123" ) ;
456
465
field_type. update_value ( & bson_value) ;
@@ -459,7 +468,7 @@ mod tests {
459
468
460
469
// #[bench]
461
470
// fn bench_it_updates_value_some(bench: &mut Bencher) {
462
- // let bson_value = Bson::I32 (1234);
471
+ // let bson_value = Bson::Int32 (1234);
463
472
// let mut field_type =
464
473
// FieldType::new("address", &Bson::String("Oranienstr. 123".to_string()));
465
474
// bench.iter(|| field_type.update_value(&bson_value));
0 commit comments