From 43bc9902752cd88cd68917e00afaff39273d3e2c Mon Sep 17 00:00:00 2001 From: asonix Date: Thu, 21 May 2020 15:02:48 -0500 Subject: [PATCH] Add is_kind for BaseExt --- src/base.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/base.rs b/src/base.rs index 524be17..0afb6e7 100644 --- a/src/base.rs +++ b/src/base.rs @@ -336,6 +336,31 @@ pub trait BaseExt: AsBase { 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 = 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 /// /// This overwrites the contents of kind