Add is_kind for BaseExt

This commit is contained in:
asonix 2020-05-21 15:02:48 -05:00
parent d54c647518
commit 43bc990275

View file

@ -336,6 +336,31 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
self.base_ref().kind.as_ref() self.base_ref().kind.as_ref()
} }
/// Check if the provide Kind is equal to the object's Kind
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams_new::{base::Base, prelude::*};
///
/// #[derive(PartialEq, serde::Deserialize)]
/// pub enum ValidKinds {
/// Video,
/// Image,
/// }
///
/// let video: Base<ValidKinds> = serde_json::from_str(r#"{"type":"Video"}"#)?;
///
/// assert!(video.is_kind(&ValidKinds::Video));
/// # Ok(())
/// # }
/// ```
fn is_kind(&self, kind: &Kind) -> bool
where
Kind: PartialEq,
{
self.kind() == Some(kind)
}
/// Set the kind for the current object /// Set the kind for the current object
/// ///
/// This overwrites the contents of kind /// This overwrites the contents of kind