@@ -1023,7 +1023,7 @@ impl Json {
10231023 self . as_object ( ) . is_some ( )
10241024 }
10251025
1026- /// If the Json value is an Object, returns the associated BTreeMap.
1026+ /// If the Json value is an Object, returns a reference to the associated BTreeMap.
10271027 /// Returns None otherwise.
10281028 pub fn as_object < ' a > ( & ' a self ) -> Option < & ' a Object > {
10291029 match self {
@@ -1032,7 +1032,7 @@ impl Json {
10321032 }
10331033 }
10341034
1035- /// If the Json value is an Object, returns the associated mutable BTreeMap.
1035+ /// If the Json value is an Object, returns a mutable reference to the associated BTreeMap.
10361036 /// Returns None otherwise.
10371037 pub fn as_object_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut Object > {
10381038 match self {
@@ -1041,12 +1041,21 @@ impl Json {
10411041 }
10421042 }
10431043
1044+ /// If the Json value is an Object, returns the associated BTreeMap.
1045+ /// Returns None otherwise.
1046+ pub fn into_object ( self ) -> Option < Object > {
1047+ match self {
1048+ Json :: Object ( map) => Some ( map) ,
1049+ _ => None
1050+ }
1051+ }
1052+
10441053 /// Returns true if the Json value is an Array. Returns false otherwise.
10451054 pub fn is_array < ' a > ( & ' a self ) -> bool {
10461055 self . as_array ( ) . is_some ( )
10471056 }
10481057
1049- /// If the Json value is an Array, returns the associated vector.
1058+ /// If the Json value is an Array, returns a reference to the associated vector.
10501059 /// Returns None otherwise.
10511060 pub fn as_array < ' a > ( & ' a self ) -> Option < & ' a Array > {
10521061 match self {
@@ -1055,7 +1064,7 @@ impl Json {
10551064 }
10561065 }
10571066
1058- /// If the Json value is an Array, returns the associated mutable vector.
1067+ /// If the Json value is an Array, returns a mutable reference to the associated vector.
10591068 /// Returns None otherwise.
10601069 pub fn as_array_mut < ' a > ( & ' a mut self ) -> Option < & ' a mut Array > {
10611070 match self {
@@ -1064,6 +1073,15 @@ impl Json {
10641073 }
10651074 }
10661075
1076+ /// If the Json value is an Array, returns the associated vector.
1077+ /// Returns None otherwise.
1078+ pub fn into_array ( self ) -> Option < Array > {
1079+ match self {
1080+ Json :: Array ( array) => Some ( array) ,
1081+ _ => None
1082+ }
1083+ }
1084+
10671085 /// Returns true if the Json value is a String. Returns false otherwise.
10681086 pub fn is_string < ' a > ( & ' a self ) -> bool {
10691087 self . as_string ( ) . is_some ( )
@@ -3426,7 +3444,7 @@ mod tests {
34263444 _ => { } // it parsed and we are good to go
34273445 }
34283446 }
3429-
3447+
34303448 #[ test]
34313449 fn test_negative_zero ( ) {
34323450 Json :: from_str ( "{\" test\" :-0}" ) . unwrap ( ) ;
0 commit comments