Add is_kind for BaseExt
This commit is contained in:
parent
d54c647518
commit
43bc990275
1 changed files with 25 additions and 0 deletions
25
src/base.rs
25
src/base.rs
|
@ -336,6 +336,31 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
|
|||
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
|
||||
///
|
||||
/// This overwrites the contents of kind
|
||||
|
|
Loading…
Reference in a new issue