serde: Add as_array_mut and as_object_mut methods to CanonicalJsonValue

This commit is contained in:
Jonas Platte 2021-05-07 23:20:49 +02:00
parent 24154195a0
commit 3b6a719b8e
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -119,6 +119,22 @@ impl CanonicalJsonValue {
_ => None,
}
}
/// If the `CanonicalJsonValue` is an `Array`, return a mutable reference to the inner value.
pub fn as_array_mut(&mut self) -> Option<&mut Vec<CanonicalJsonValue>> {
match self {
Self::Array(a) => Some(a),
_ => None,
}
}
/// If the `CanonicalJsonValue` is an `Object`, return a mutable reference to the inner value.
pub fn as_object_mut(&mut self) -> Option<&mut Object> {
match self {
Self::Object(o) => Some(o),
_ => None,
}
}
}
impl Default for CanonicalJsonValue {