@@ -207,7 +207,17 @@ impl OrderedDocument {
207207 }
208208 }
209209
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.
211221 pub fn get_decimal128 ( & self , key : & str ) -> ValueAccessResult < & Decimal128 > {
212222 match self . get ( key) {
213223 Some ( & Bson :: Decimal128 ( ref v) ) => Ok ( v) ,
@@ -216,6 +226,15 @@ impl OrderedDocument {
216226 }
217227 }
218228
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+
219238 /// Get a string slice this key if it exists and has the correct type.
220239 pub fn get_str ( & self , key : & str ) -> ValueAccessResult < & str > {
221240 match self . get ( key) {
@@ -225,6 +244,15 @@ impl OrderedDocument {
225244 }
226245 }
227246
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+
228256 /// Get a reference to an array for this key if it exists and has
229257 /// the correct type.
230258 pub fn get_array ( & self , key : & str ) -> ValueAccessResult < & Array > {
@@ -235,6 +263,16 @@ impl OrderedDocument {
235263 }
236264 }
237265
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+
238276 /// Get a reference to a document for this key if it exists and has
239277 /// the correct type.
240278 pub fn get_document ( & self , key : & str ) -> ValueAccessResult < & Document > {
@@ -245,6 +283,16 @@ impl OrderedDocument {
245283 }
246284 }
247285
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+
248296 /// Get a bool value for this key if it exists and has the correct type.
249297 pub fn get_bool ( & self , key : & str ) -> ValueAccessResult < bool > {
250298 match self . get ( key) {
@@ -254,6 +302,15 @@ impl OrderedDocument {
254302 }
255303 }
256304
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+
257314 /// Returns wether this key has a null value
258315 pub fn is_null ( & self , key : & str ) -> bool {
259316 self . get ( key) == Some ( & Bson :: Null )
@@ -268,6 +325,15 @@ impl OrderedDocument {
268325 }
269326 }
270327
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+
271337 /// Get an i64 value for this key if it exists and has the correct type.
272338 pub fn get_i64 ( & self , key : & str ) -> ValueAccessResult < i64 > {
273339 match self . get ( key) {
@@ -277,6 +343,15 @@ impl OrderedDocument {
277343 }
278344 }
279345
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+
280355 /// Get a time stamp value for this key if it exists and has the correct type.
281356 pub fn get_time_stamp ( & self , key : & str ) -> ValueAccessResult < i64 > {
282357 match self . get ( key) {
@@ -286,7 +361,16 @@ impl OrderedDocument {
286361 }
287362 }
288363
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.
290374 pub fn get_binary_generic ( & self , key : & str ) -> ValueAccessResult < & Vec < u8 > > {
291375 match self . get ( key) {
292376 Some ( & Bson :: Binary ( BinarySubtype :: Generic , ref v) ) => Ok ( v) ,
@@ -295,7 +379,16 @@ impl OrderedDocument {
295379 }
296380 }
297381
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.
299392 pub fn get_object_id ( & self , key : & str ) -> ValueAccessResult < & ObjectId > {
300393 match self . get ( key) {
301394 Some ( & Bson :: ObjectId ( ref v) ) => Ok ( v) ,
@@ -304,7 +397,16 @@ impl OrderedDocument {
304397 }
305398 }
306399
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.
308410 pub fn get_utc_datetime ( & self , key : & str ) -> ValueAccessResult < & DateTime < Utc > > {
309411 match self . get ( key) {
310412 Some ( & Bson :: UtcDatetime ( ref v) ) => Ok ( v) ,
@@ -313,6 +415,15 @@ impl OrderedDocument {
313415 }
314416 }
315417
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+
316427 /// Returns true if the map contains a value for the specified key.
317428 pub fn contains_key ( & self , key : & str ) -> bool {
318429 self . inner . contains_key ( key)
@@ -442,4 +553,4 @@ impl Extend<(String, Bson)> for OrderedDocument {
442553 self . insert ( k, v) ;
443554 }
444555 }
445- }
556+ }
0 commit comments