diff --git a/src/object.rs b/src/object.rs index d39397c..eed06fa 100644 --- a/src/object.rs +++ b/src/object.rs @@ -387,6 +387,154 @@ pub trait ObjectExt: AsObject { self } + /// Fetch the icon for the current object + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(icon) = video.icon() { + /// println!("{:?}", icon); + /// } + /// ``` + fn icon<'a>(&'a self) -> Option<&'a OneOrMany> + where + Kind: 'a, + { + self.object_ref().icon.as_ref() + } + + /// Set the icon for the current object + /// + /// This overwrites the contents of icon + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_icon("https://example.com".parse::()?); + /// # Ok(()) + /// # } + /// ``` + fn set_icon(&mut self, icon: T) -> &mut Self + where + T: Into, + { + self.object_mut().icon = Some(icon.into().into()); + self + } + + /// Set many icons for the current object + /// + /// This overwrites the contents of icon + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_many_icons(vec![ + /// "https://example.com/one".parse::()?, + /// "https://example.com/two".parse()?, + /// ]); + /// # Ok(()) + /// # } + /// ``` + fn set_many_icons(&mut self, items: I) -> &mut Self + where + I: IntoIterator, + T: Into, + { + let v: Vec<_> = items.into_iter().map(Into::into).collect(); + self.object_mut().icon = Some(v.into()); + self + } + + /// Add a icon to the current object + /// + /// This does not overwrite the contents of icon, only appends an item + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video + /// .add_icon("https://example.com/one".parse::()?) + /// .add_icon("https://example.com/two".parse::()?); + /// # Ok(()) + /// # } + /// ``` + fn add_icon(&mut self, icon: T) -> &mut Self + where + T: Into, + { + let a = match self.object_mut().icon.take() { + Some(mut a) => { + a.add(icon.into()); + a + } + None => vec![icon.into()].into(), + }; + self.object_mut().icon = Some(a); + self + } + + /// Take the icon from the current object, leaving nothing + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(icon) = video.take_icon() { + /// println!("{:?}", icon); + /// } + /// ``` + fn take_icon(&mut self) -> Option> { + self.object_mut().icon.take() + } + + /// Delete the icon from the current object + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// # video.set_icon("https://example.com".parse::()?); + /// # + /// use activitystreams_new::prelude::*; + /// + /// assert!(video.icon().is_some()); + /// video.delete_icon(); + /// assert!(video.icon().is_none()); + /// # Ok(()) + /// # } + /// ``` + fn delete_icon(&mut self) -> &mut Self { + self.object_mut().icon = None; + self + } + + /// Fetch the image for the current object + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(image) = video.image() { + /// println!("{:?}", image); + /// } + /// ``` fn image<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, @@ -394,6 +542,20 @@ pub trait ObjectExt: AsObject { self.object_ref().image.as_ref() } + /// Set the image for the current object + /// + /// This overwrites the contents of image + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_image("https://example.com".parse::()?); + /// # Ok(()) + /// # } + /// ``` fn set_image(&mut self, image: T) -> &mut Self where T: Into, @@ -402,6 +564,23 @@ pub trait ObjectExt: AsObject { self } + /// Set many images for the current object + /// + /// This overwrites the contents of image + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_many_images(vec![ + /// "https://example.com/one".parse::()?, + /// "https://example.com/two".parse()?, + /// ]); + /// # Ok(()) + /// # } + /// ``` fn set_many_images(&mut self, items: I) -> &mut Self where I: IntoIterator, @@ -412,6 +591,22 @@ pub trait ObjectExt: AsObject { self } + /// Add a image to the current object + /// + /// This does not overwrite the contents of image, only appends an item + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video + /// .add_image("https://example.com/one".parse::()?) + /// .add_image("https://example.com/two".parse::()?); + /// # Ok(()) + /// # } + /// ``` fn add_image(&mut self, image: T) -> &mut Self where T: Into, @@ -427,10 +622,38 @@ pub trait ObjectExt: AsObject { self } + /// Take the image from the current object, leaving nothing + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(image) = video.take_image() { + /// println!("{:?}", image); + /// } + /// ``` fn take_image(&mut self) -> Option> { self.object_mut().image.take() } + /// Delete the image from the current object + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// # video.set_image("https://example.com".parse::()?); + /// # + /// use activitystreams_new::prelude::*; + /// + /// assert!(video.image().is_some()); + /// video.delete_image(); + /// assert!(video.image().is_none()); + /// # Ok(()) + /// # } + /// ``` fn delete_image(&mut self) -> &mut Self { self.object_mut().image = None; self @@ -485,6 +708,142 @@ pub trait ObjectExt: AsObject { self } + /// Fetch the tag for the current object + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(tag) = video.tag() { + /// println!("{:?}", tag); + /// } + /// ``` + fn tag<'a>(&'a self) -> Option<&'a OneOrMany> + where + Kind: 'a, + { + self.object_ref().tag.as_ref() + } + + /// Set the tag for the current object + /// + /// This overwrites the contents of tag + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_tag("https://example.com".parse::()?); + /// # Ok(()) + /// # } + /// ``` + fn set_tag(&mut self, tag: T) -> &mut Self + where + T: Into, + { + self.object_mut().tag = Some(tag.into().into()); + self + } + + /// Set many tags for the current object + /// + /// This overwrites the contents of tag + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video.set_many_tags(vec![ + /// "https://example.com/one".parse::()?, + /// "https://example.com/two".parse()?, + /// ]); + /// # Ok(()) + /// # } + /// ``` + fn set_many_tags(&mut self, items: I) -> &mut Self + where + I: IntoIterator, + T: Into, + { + let v: Vec<_> = items.into_iter().map(Into::into).collect(); + self.object_mut().tag = Some(v.into()); + self + } + + /// Add a tag to the current object + /// + /// This does not overwrite the contents of tag, only appends an item + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// use activitystreams_new::prelude::*; + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// + /// video + /// .add_tag("https://example.com/one".parse::()?) + /// .add_tag("https://example.com/two".parse::()?); + /// # Ok(()) + /// # } + /// ``` + fn add_tag(&mut self, tag: T) -> &mut Self + where + T: Into, + { + let a = match self.object_mut().tag.take() { + Some(mut a) => { + a.add(tag.into()); + a + } + None => vec![tag.into()].into(), + }; + self.object_mut().tag = Some(a); + self + } + + /// Take the tag from the current object, leaving nothing + /// + /// ```rust + /// # use activitystreams_new::object::Video; + /// # let mut video = Video::default(); + /// # + /// use activitystreams_new::prelude::*; + /// + /// if let Some(tag) = video.take_tag() { + /// println!("{:?}", tag); + /// } + /// ``` + fn take_tag(&mut self) -> Option> { + self.object_mut().tag.take() + } + + /// Delete the tag from the current object + /// + /// ```rust + /// # fn main() -> Result<(), anyhow::Error> { + /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; + /// # let mut video = Video::default(); + /// # video.set_tag("https://example.com".parse::()?); + /// # + /// use activitystreams_new::prelude::*; + /// + /// assert!(video.tag().is_some()); + /// video.delete_tag(); + /// assert!(video.tag().is_none()); + /// # Ok(()) + /// # } + /// ``` + fn delete_tag(&mut self) -> &mut Self { + self.object_mut().tag = None; + self + } + fn start_time<'a>(&'a self) -> Option<&'a XsdDateTime> where Kind: 'a,