@@ -207,7 +207,17 @@ impl OrderedDocument {
207
207
}
208
208
}
209
209
210
- /// Get Decimal128 value for key, if it exists.
210
+ /// Get a mutable reference to a floating point value for this key if it exists and has
211
+ /// the correct type.
212
+ pub fn get_f64_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut f64 > {
213
+ match self . get_mut ( key) {
214
+ Some ( & mut Bson :: FloatingPoint ( ref mut v) ) => Ok ( v) ,
215
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
216
+ None => Err ( ValueAccessError :: NotPresent ) ,
217
+ }
218
+ }
219
+
220
+ /// Get a reference to a Decimal128 value for key, if it exists.
211
221
pub fn get_decimal128 ( & self , key : & str ) -> ValueAccessResult < & Decimal128 > {
212
222
match self . get ( key) {
213
223
Some ( & Bson :: Decimal128 ( ref v) ) => Ok ( v) ,
@@ -216,6 +226,15 @@ impl OrderedDocument {
216
226
}
217
227
}
218
228
229
+ /// Get a mutable reference to a Decimal128 value for key, if it exists.
230
+ pub fn get_decimal128_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut Decimal128 > {
231
+ match self . get_mut ( key) {
232
+ Some ( & mut Bson :: Decimal128 ( ref mut v) ) => Ok ( v) ,
233
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
234
+ None => Err ( ValueAccessError :: NotPresent ) ,
235
+ }
236
+ }
237
+
219
238
/// Get a string slice this key if it exists and has the correct type.
220
239
pub fn get_str ( & self , key : & str ) -> ValueAccessResult < & str > {
221
240
match self . get ( key) {
@@ -225,6 +244,15 @@ impl OrderedDocument {
225
244
}
226
245
}
227
246
247
+ /// Get a mutable string slice this key if it exists and has the correct type.
248
+ pub fn get_str_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut str > {
249
+ match self . get_mut ( key) {
250
+ Some ( & mut Bson :: String ( ref mut v) ) => Ok ( v) ,
251
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
252
+ None => Err ( ValueAccessError :: NotPresent ) ,
253
+ }
254
+ }
255
+
228
256
/// Get a reference to an array for this key if it exists and has
229
257
/// the correct type.
230
258
pub fn get_array ( & self , key : & str ) -> ValueAccessResult < & Array > {
@@ -235,6 +263,16 @@ impl OrderedDocument {
235
263
}
236
264
}
237
265
266
+ /// Get a mutable reference to an array for this key if it exists and has
267
+ /// the correct type.
268
+ pub fn get_array_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut Array > {
269
+ match self . get_mut ( key) {
270
+ Some ( & mut Bson :: Array ( ref mut v) ) => Ok ( v) ,
271
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
272
+ None => Err ( ValueAccessError :: NotPresent ) ,
273
+ }
274
+ }
275
+
238
276
/// Get a reference to a document for this key if it exists and has
239
277
/// the correct type.
240
278
pub fn get_document ( & self , key : & str ) -> ValueAccessResult < & Document > {
@@ -245,6 +283,16 @@ impl OrderedDocument {
245
283
}
246
284
}
247
285
286
+ /// Get a mutable reference to a document for this key if it exists and has
287
+ /// the correct type.
288
+ pub fn get_document_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut Document > {
289
+ match self . get_mut ( key) {
290
+ Some ( & mut Bson :: Document ( ref mut v) ) => Ok ( v) ,
291
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
292
+ None => Err ( ValueAccessError :: NotPresent ) ,
293
+ }
294
+ }
295
+
248
296
/// Get a bool value for this key if it exists and has the correct type.
249
297
pub fn get_bool ( & self , key : & str ) -> ValueAccessResult < bool > {
250
298
match self . get ( key) {
@@ -254,6 +302,15 @@ impl OrderedDocument {
254
302
}
255
303
}
256
304
305
+ /// Get a mutable reference to a bool value for this key if it exists and has the correct type.
306
+ pub fn get_bool_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut bool > {
307
+ match self . get_mut ( key) {
308
+ Some ( & mut Bson :: Boolean ( ref mut v) ) => Ok ( v) ,
309
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
310
+ None => Err ( ValueAccessError :: NotPresent ) ,
311
+ }
312
+ }
313
+
257
314
/// Returns wether this key has a null value
258
315
pub fn is_null ( & self , key : & str ) -> bool {
259
316
self . get ( key) == Some ( & Bson :: Null )
@@ -268,6 +325,15 @@ impl OrderedDocument {
268
325
}
269
326
}
270
327
328
+ /// Get a mutable reference to an i32 value for this key if it exists and has the correct type.
329
+ pub fn get_i32_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut i32 > {
330
+ match self . get_mut ( key) {
331
+ Some ( & mut Bson :: I32 ( ref mut v) ) => Ok ( v) ,
332
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
333
+ None => Err ( ValueAccessError :: NotPresent ) ,
334
+ }
335
+ }
336
+
271
337
/// Get an i64 value for this key if it exists and has the correct type.
272
338
pub fn get_i64 ( & self , key : & str ) -> ValueAccessResult < i64 > {
273
339
match self . get ( key) {
@@ -277,6 +343,15 @@ impl OrderedDocument {
277
343
}
278
344
}
279
345
346
+ /// Get a mutable reference to an i64 value for this key if it exists and has the correct type.
347
+ pub fn get_i64_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut i64 > {
348
+ match self . get_mut ( key) {
349
+ Some ( & mut Bson :: I64 ( ref mut v) ) => Ok ( v) ,
350
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
351
+ None => Err ( ValueAccessError :: NotPresent ) ,
352
+ }
353
+ }
354
+
280
355
/// Get a time stamp value for this key if it exists and has the correct type.
281
356
pub fn get_time_stamp ( & self , key : & str ) -> ValueAccessResult < i64 > {
282
357
match self . get ( key) {
@@ -286,7 +361,16 @@ impl OrderedDocument {
286
361
}
287
362
}
288
363
289
- /// Get a generic binary value for this key if it exists and has the correct type.
364
+ /// Get a mutable reference to a time stamp value for this key if it exists and has the correct type.
365
+ pub fn get_time_stamp_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut i64 > {
366
+ match self . get_mut ( key) {
367
+ Some ( & mut Bson :: TimeStamp ( ref mut v) ) => Ok ( v) ,
368
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
369
+ None => Err ( ValueAccessError :: NotPresent ) ,
370
+ }
371
+ }
372
+
373
+ /// Get a reference to a generic binary value for this key if it exists and has the correct type.
290
374
pub fn get_binary_generic ( & self , key : & str ) -> ValueAccessResult < & Vec < u8 > > {
291
375
match self . get ( key) {
292
376
Some ( & Bson :: Binary ( BinarySubtype :: Generic , ref v) ) => Ok ( v) ,
@@ -295,7 +379,16 @@ impl OrderedDocument {
295
379
}
296
380
}
297
381
298
- /// Get an object id value for this key if it exists and has the correct type.
382
+ /// Get a mutable reference generic binary value for this key if it exists and has the correct type.
383
+ pub fn get_binary_generic_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut Vec < u8 > > {
384
+ match self . get_mut ( key) {
385
+ Some ( & mut Bson :: Binary ( BinarySubtype :: Generic , ref mut v) ) => Ok ( v) ,
386
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
387
+ None => Err ( ValueAccessError :: NotPresent ) ,
388
+ }
389
+ }
390
+
391
+ /// Get a reference to an object id value for this key if it exists and has the correct type.
299
392
pub fn get_object_id ( & self , key : & str ) -> ValueAccessResult < & ObjectId > {
300
393
match self . get ( key) {
301
394
Some ( & Bson :: ObjectId ( ref v) ) => Ok ( v) ,
@@ -304,7 +397,16 @@ impl OrderedDocument {
304
397
}
305
398
}
306
399
307
- /// Get a UTC datetime value for this key if it exists and has the correct type.
400
+ /// Get a mutable reference to an object id value for this key if it exists and has the correct type.
401
+ pub fn get_object_id_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut ObjectId > {
402
+ match self . get_mut ( key) {
403
+ Some ( & mut Bson :: ObjectId ( ref mut v) ) => Ok ( v) ,
404
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
405
+ None => Err ( ValueAccessError :: NotPresent ) ,
406
+ }
407
+ }
408
+
409
+ /// Get a reference to a UTC datetime value for this key if it exists and has the correct type.
308
410
pub fn get_utc_datetime ( & self , key : & str ) -> ValueAccessResult < & DateTime < Utc > > {
309
411
match self . get ( key) {
310
412
Some ( & Bson :: UtcDatetime ( ref v) ) => Ok ( v) ,
@@ -313,6 +415,15 @@ impl OrderedDocument {
313
415
}
314
416
}
315
417
418
+ /// Get a mutable reference to a UTC datetime value for this key if it exists and has the correct type.
419
+ pub fn get_utc_datetime_mut ( & mut self , key : & str ) -> ValueAccessResult < & mut DateTime < Utc > > {
420
+ match self . get_mut ( key) {
421
+ Some ( & mut Bson :: UtcDatetime ( ref mut v) ) => Ok ( v) ,
422
+ Some ( _) => Err ( ValueAccessError :: UnexpectedType ) ,
423
+ None => Err ( ValueAccessError :: NotPresent ) ,
424
+ }
425
+ }
426
+
316
427
/// Returns true if the map contains a value for the specified key.
317
428
pub fn contains_key ( & self , key : & str ) -> bool {
318
429
self . inner . contains_key ( key)
@@ -442,4 +553,4 @@ impl Extend<(String, Bson)> for OrderedDocument {
442
553
self . insert ( k, v) ;
443
554
}
444
555
}
445
- }
556
+ }
0 commit comments