serde: Add is_* methods to CanonicalJsonValue

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

View File

@ -135,6 +135,31 @@ impl CanonicalJsonValue {
_ => None,
}
}
/// Returns `true` if the `CanonicalJsonValue` is a `Bool`.
pub fn is_bool(&self) -> bool {
matches!(self, Self::Bool(_))
}
/// Returns `true` if the `CanonicalJsonValue` is an `Integer`.
pub fn is_integer(&self) -> bool {
matches!(self, Self::Integer(_))
}
/// Returns `true` if the `CanonicalJsonValue` is a `String`.
pub fn is_string(&self) -> bool {
matches!(self, Self::String(_))
}
/// Returns `true` if the `CanonicalJsonValue` is an `Array`.
pub fn is_array(&self) -> bool {
matches!(self, Self::Array(_))
}
/// Returns `true` if the `CanonicalJsonValue` is an `Object`.
pub fn is_object(&self) -> bool {
matches!(self, Self::Object(_))
}
}
impl Default for CanonicalJsonValue {