//! Types and traits for dealing with Object attributes //! //! ```rust //! # fn main() -> Result<(), anyhow::Error> { //! use activitystreams_new::{ //! object::Image, //! prelude::*, //! primitives::XsdAnyUri, //! }; //! //! let mut image = Image::default(); //! //! image //! .set_url("https://example.com/image.png".parse::()?) //! .set_attributed_to("https://example.com/actor".parse::()?) //! .set_generator("https://example.com/image-generator".parse::()?) //! .set_icon("https://example.com/icon.png".parse::()?); //! # //! # Ok(()) //! # } //! ``` use crate::{ base::{AnyBase, AsBase, Base, Extends}, markers, primitives::{AnyString, OneOrMany, Unit, XsdAnyUri, XsdDateTime, XsdDuration, XsdFloat}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, }; use std::convert::TryFrom; use typed_builder::TypedBuilder; pub mod kind { //! Kinds of objects defined by the spec //! //! These types exist only to be statically-typed versions of the associated string. e.g. //! `PlaceType` -> `"Place"` pub use activitystreams::object::kind::*; } use self::kind::*; /// Implementation trait for deriving Object methods for a type /// /// Any type implementing AsObject will automatically gain methods provided by ObjectExt pub trait AsObject: markers::Object { /// Immutable borrow of `Object` fn object_ref(&self) -> &Object; /// Mutable borrow of `Object` fn object_mut(&mut self) -> &mut Object; } /// Implementation trait for deriving ActivityPub Object methods for a type /// /// Any type implementing AsApObject will automatically gain methods provided by ApObjectExt pub trait AsApObject: markers::Object { /// Immutable borrow of `ApObject` fn ap_object_ref(&self) -> &ApObject; /// Mutable borrow of `ApObject` fn ap_object_mut(&mut self) -> &mut ApObject; } /// Implementation trait for deriving Place methods for a type /// /// Any type implementing AsPlace will automatically gain methods provided by PlaceExt pub trait AsPlace: markers::Object { /// Immutable borrow of `Place` fn place_ref(&self) -> &Place; /// Mutable borrow of `Place` fn place_mut(&mut self) -> &mut Place; } /// Implementation trait for deriving Profile methods for a type /// /// Any type implementing AsProfile will automatically gain methods provided by ProfileExt pub trait AsProfile: markers::Object { /// Immutable borrow of `Profile` fn profile_ref(&self) -> &Profile; /// Mutable borrow of `Profile` fn profile_mut(&mut self) -> &mut Profile; } /// Implementation trait for deriving Relationship methods for a type /// /// Any type implementing AsRelationship will automatically gain methods provided by /// RelationshipExt pub trait AsRelationship: markers::Object { /// Immutable borrow of `Relationship` fn relationship_ref(&self) -> &Relationship; /// Mutable borrow of `Relationship` fn relationship_mut(&mut self) -> &mut Relationship; } /// Implementation trait for deriving Tombstone methods for a type /// /// Any type implementing AsTombstone will automatically gain methods provided by TombstoneExt pub trait AsTombstone: markers::Object { /// Immutable borrow of `Tombstone` fn tombstone_ref(&self) -> &Tombstone; /// Mutable borrow of `Tombstone` fn tombstone_mut(&mut self) -> &mut Tombstone; } /// Helper methods for interacting with Object types /// /// This trait represents methods valid for any ActivityStreams Object. /// /// Documentation for the fields related to these methods can be found on the `Object` struct pub trait ObjectExt: AsObject { /// Fetch the attachment for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(attachment) = video.attachment() { /// println!("{:?}", attachment); /// } /// ``` fn attachment<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().attachment.as_ref() } /// Set the attachment for the current object /// /// This overwrites the contents of attachment /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_attachment("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_attachment(&mut self, attachment: T) -> &mut Self where T: Into, { self.object_mut().attachment = Some(attachment.into().into()); self } /// Set many attachments for the current object /// /// This overwrites the contents of attachment /// /// ```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_attachments(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_attachments(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().attachment = Some(v.into()); self } /// Add a attachment to the current object /// /// This does not overwrite the contents of attachment, 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_attachment("https://example.com/one".parse::()?) /// .add_attachment("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_attachment(&mut self, attachment: T) -> &mut Self where T: Into, { let a = match self.object_mut().attachment.take() { Some(mut a) => { a.add(attachment.into()); a } None => vec![attachment.into()].into(), }; self.object_mut().attachment = Some(a); self } /// Take the attachment from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(attachment) = video.take_attachment() { /// println!("{:?}", attachment); /// } /// ``` fn take_attachment(&mut self) -> Option> { self.object_mut().attachment.take() } /// Delete the attachment from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_attachment("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.attachment().is_some()); /// video.delete_attachment(); /// assert!(video.attachment().is_none()); /// # Ok(()) /// # } /// ``` fn delete_attachment(&mut self) -> &mut Self { self.object_mut().attachment = None; self } /// Fetch the attributed_to for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(attributed_to) = video.attributed_to() { /// println!("{:?}", attributed_to); /// } /// ``` fn attributed_to<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().attributed_to.as_ref() } /// Set the attributed_to for the current object /// /// This overwrites the contents of attributed_to /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_attributed_to("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_attributed_to(&mut self, attributed_to: T) -> &mut Self where T: Into, { self.object_mut().attributed_to = Some(attributed_to.into().into()); self } /// Set many attributed_tos for the current object /// /// This overwrites the contents of attributed_to /// /// ```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_attributed_tos(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_attributed_tos(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().attributed_to = Some(v.into()); self } /// Add a attributed_to to the current object /// /// This does not overwrite the contents of attributed_to, 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_attributed_to("https://example.com/one".parse::()?) /// .add_attributed_to("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_attributed_to(&mut self, attributed_to: T) -> &mut Self where T: Into, { let a = match self.object_mut().attributed_to.take() { Some(mut a) => { a.add(attributed_to.into()); a } None => vec![attributed_to.into()].into(), }; self.object_mut().attributed_to = Some(a); self } /// Take the attributed_to from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(attributed_to) = video.take_attributed_to() { /// println!("{:?}", attributed_to); /// } /// ``` fn take_attributed_to(&mut self) -> Option> { self.object_mut().attributed_to.take() } /// Delete the attributed_to from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_attributed_to("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.attributed_to().is_some()); /// video.delete_attributed_to(); /// assert!(video.attributed_to().is_none()); /// # Ok(()) /// # } /// ``` fn delete_attributed_to(&mut self) -> &mut Self { self.object_mut().attributed_to = None; self } /// Fetch the audience for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(audience) = video.audience() { /// println!("{:?}", audience); /// } /// ``` fn audience<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().audience.as_ref() } /// Set the audience for the current object /// /// This overwrites the contents of audience /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_audience("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_audience(&mut self, audience: T) -> &mut Self where T: Into, { self.object_mut().audience = Some(audience.into().into()); self } /// This overwrites the contents of audience /// /// ```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_audiences(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_audiences(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().audience = Some(v.into()); self } /// Add a audience to the current object /// /// This does not overwrite the contents of audience, 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_audience("https://example.com/one".parse::()?) /// .add_audience("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_audience(&mut self, audience: T) -> &mut Self where T: Into, { let a = match self.object_mut().audience.take() { Some(mut a) => { a.add(audience.into()); a } None => vec![audience.into()].into(), }; self.object_mut().audience = Some(a); self } /// Take the audience from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(audience) = video.take_audience() { /// println!("{:?}", audience); /// } /// ``` fn take_audience(&mut self) -> Option> { self.object_mut().audience.take() } /// Delete the audience from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_audience("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.audience().is_some()); /// video.delete_audience(); /// assert!(video.audience().is_none()); /// # Ok(()) /// # } /// ``` fn delete_audience(&mut self) -> &mut Self { self.object_mut().audience = None; self } /// Fetch the content for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(content) = video.content() { /// println!("{:?}", content); /// } /// ``` fn content<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().content.as_ref() } /// Set the content for the current object /// /// This overwrites the contents of content /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video.set_content(XsdString::from("hi")); /// ``` fn set_content(&mut self, content: T) -> &mut Self where T: Into, { self.object_mut().content = Some(content.into().into()); self } /// Set many contents for the current object /// /// This overwrites the contents of content /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video.set_many_contents(vec![ /// XsdString::from("hi"), /// "hello".into(), /// ]); /// ``` fn set_many_contents(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().content = Some(v.into()); self } /// Add a content to the current object /// /// This does not overwrite the contents of content, only appends an item /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video /// .add_content(XsdString::from("hi")) /// .add_content(XsdString::from("hello")); /// ``` fn add_content(&mut self, content: T) -> &mut Self where T: Into, { let a = match self.object_mut().content.take() { Some(mut a) => { a.add(content.into()); a } None => vec![content.into()].into(), }; self.object_mut().content = Some(a); self } /// Take the content from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(content) = video.take_content() { /// println!("{:?}", content); /// } /// ``` fn take_content(&mut self) -> Option> { self.object_mut().content.take() } /// Delete the content from the current object /// /// ```rust /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// # video.set_content(XsdString::from("https://example.com")); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.content().is_some()); /// video.delete_content(); /// assert!(video.content().is_none()); /// ``` fn delete_content(&mut self) -> &mut Self { self.object_mut().content = None; self } /// Fetch the summary for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(summary) = video.summary() { /// println!("{:?}", summary); /// } /// ``` fn summary<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().summary.as_ref() } /// Set the summary for the current object /// /// This overwrites the contents of summary /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video.set_summary(XsdString::from("hi")); /// ``` fn set_summary(&mut self, summary: T) -> &mut Self where T: Into, { self.object_mut().summary = Some(summary.into().into()); self } /// Set many summaries for the current object /// /// This overwrites the contents of summary /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video.set_many_summaries(vec![ /// XsdString::from("hi"), /// "hello".into(), /// ]); /// ``` fn set_many_summaries(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().summary = Some(v.into()); self } /// Add a summary to the current object /// /// This does not overwrite the contents of summary, only appends an item /// /// ```rust /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// /// video /// .add_summary(XsdString::from("hi")) /// .add_summary(XsdString::from("hello")); /// ``` fn add_summary(&mut self, summary: T) -> &mut Self where T: Into, { let a = match self.object_mut().summary.take() { Some(mut a) => { a.add(summary.into()); a } None => vec![summary.into()].into(), }; self.object_mut().summary = Some(a); self } /// Take the summary from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(summary) = video.take_summary() { /// println!("{:?}", summary); /// } /// ``` fn take_summary(&mut self) -> Option> { self.object_mut().summary.take() } /// Delete the summary from the current object /// /// ```rust /// # use activitystreams_new::{object::Video, primitives::XsdString}; /// # let mut video = Video::default(); /// # video.set_summary(XsdString::from("https://example.com")); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.summary().is_some()); /// video.delete_summary(); /// assert!(video.summary().is_none()); /// ``` fn delete_summary(&mut self) -> &mut Self { self.object_mut().summary = None; self } /// Fetch the url for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(url) = video.url() { /// println!("{:?}", url); /// } /// ``` fn url<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().url.as_ref() } /// Set the url for the current object /// /// This overwrites the contents of url /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_url("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_url(&mut self, url: T) -> &mut Self where T: Into, { self.object_mut().url = Some(url.into().into()); self } /// Set many urls for the current object /// /// This overwrites the contents of url /// /// ```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_urls(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_urls(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().url = Some(v.into()); self } /// Add a url to the current object /// /// This does not overwrite the contents of url, 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_url("https://example.com/one".parse::()?) /// .add_url("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_url(&mut self, url: T) -> &mut Self where T: Into, { let a = match self.object_mut().url.take() { Some(mut a) => { a.add(url.into()); a } None => vec![url.into()].into(), }; self.object_mut().url = Some(a); self } /// Take the url from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(url) = video.take_url() { /// println!("{:?}", url); /// } /// ``` fn take_url(&mut self) -> Option> { self.object_mut().url.take() } /// Delete the url from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_url("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.url().is_some()); /// video.delete_url(); /// assert!(video.url().is_none()); /// # Ok(()) /// # } /// ``` fn delete_url(&mut self) -> &mut Self { self.object_mut().url = None; self } /// Fetch the generator for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(generator) = video.generator() { /// println!("{:?}", generator); /// } /// ``` fn generator<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().generator.as_ref() } /// Set the generator for the current object /// /// This overwrites the contents of generator /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_generator("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_generator(&mut self, generator: T) -> &mut Self where T: Into, { self.object_mut().generator = Some(generator.into().into()); self } /// Set many generators for the current object /// /// This overwrites the contents of generator /// /// ```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_generators(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_generators(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().generator = Some(v.into()); self } /// Add a generator to the current object /// /// This does not overwrite the contents of generator, 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_generator("https://example.com/one".parse::()?) /// .add_generator("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_generator(&mut self, generator: T) -> &mut Self where T: Into, { let a = match self.object_mut().generator.take() { Some(mut a) => { a.add(generator.into()); a } None => vec![generator.into()].into(), }; self.object_mut().generator = Some(a); self } /// Take the generator from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(generator) = video.take_generator() { /// println!("{:?}", generator); /// } /// ``` fn take_generator(&mut self) -> Option> { self.object_mut().generator.take() } /// Delete the generator from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_generator("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.generator().is_some()); /// video.delete_generator(); /// assert!(video.generator().is_none()); /// # Ok(()) /// # } /// ``` fn delete_generator(&mut self) -> &mut Self { self.object_mut().generator = None; 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, { 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, { self.object_mut().image = Some(image.into().into()); 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, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().image = Some(v.into()); 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, { let a = match self.object_mut().image.take() { Some(mut a) => { a.add(image.into()); a } None => vec![image.into()].into(), }; self.object_mut().image = Some(a); 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 } /// Fetch the location for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(location) = video.location() { /// println!("{:?}", location); /// } /// ``` fn location<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().location.as_ref() } /// Set the location for the current object /// /// This overwrites the contents of location /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_location("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_location(&mut self, location: T) -> &mut Self where T: Into, { self.object_mut().location = Some(location.into().into()); self } /// Set many locations for the current object /// /// This overwrites the contents of location /// /// ```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_locations(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_locations(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().location = Some(v.into()); self } /// Add a location to the current object /// /// This does not overwrite the contents of location, 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_location("https://example.com/one".parse::()?) /// .add_location("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_location(&mut self, location: T) -> &mut Self where T: Into, { let a = match self.object_mut().location.take() { Some(mut a) => { a.add(location.into()); a } None => vec![location.into()].into(), }; self.object_mut().location = Some(a); self } /// Take the location from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(location) = video.take_location() { /// println!("{:?}", location); /// } /// ``` fn take_location(&mut self) -> Option> { self.object_mut().location.take() } /// Delete the location from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_location("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.location().is_some()); /// video.delete_location(); /// assert!(video.location().is_none()); /// # Ok(()) /// # } /// ``` fn delete_location(&mut self) -> &mut Self { self.object_mut().location = None; 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 } /// Fetch the start_time for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(start_time) = video.start_time() { /// println!("{:?}", start_time); /// } /// ``` fn start_time<'a>(&'a self) -> Option<&'a XsdDateTime> where Kind: 'a, { self.object_ref().start_time.as_ref() } /// Set the start_time for the current object /// /// This overwrites the contents of start_time /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdDateTime}; /// # let mut video = Video::default(); /// /// video.set_start_time("2020-04-20T04:20:00Z".parse()?); /// # Ok(()) /// # } /// ``` fn set_start_time(&mut self, start_time: XsdDateTime) -> &mut Self { self.object_mut().start_time = Some(start_time); self } /// Take the start_time from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(start_time) = video.take_start_time() { /// println!("{:?}", start_time); /// } /// ``` fn take_start_time(&mut self) -> Option { self.object_mut().start_time.take() } /// Delete the start_time from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_start_time("2020-04-20T04:20:00Z".parse()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.start_time().is_some()); /// video.delete_start_time(); /// assert!(video.start_time().is_none()); /// # Ok(()) /// # } /// ``` fn delete_start_time(&mut self) -> &mut Self { self.object_mut().start_time = None; self } /// Fetch the end_time for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(end_time) = video.end_time() { /// println!("{:?}", end_time); /// } /// ``` fn end_time<'a>(&'a self) -> Option<&'a XsdDateTime> where Kind: 'a, { self.object_ref().end_time.as_ref() } /// Set the end_time for the current object /// /// This overwrites the contents of end_time /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdDateTime}; /// # let mut video = Video::default(); /// /// video.set_end_time("2020-04-20T04:20:00-05:00".parse()?); /// # Ok(()) /// # } /// ``` fn set_end_time(&mut self, end_time: XsdDateTime) -> &mut Self { self.object_mut().end_time = Some(end_time); self } /// Take the end_time from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(end_time) = video.take_end_time() { /// println!("{:?}", end_time); /// } /// ``` fn take_end_time(&mut self) -> Option { self.object_mut().end_time.take() } /// Delete the end_time from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_end_time("2020-04-20T04:20:00Z".parse()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.end_time().is_some()); /// video.delete_end_time(); /// assert!(video.end_time().is_none()); /// # Ok(()) /// # } /// ``` fn delete_end_time(&mut self) -> &mut Self { self.object_mut().end_time = None; self } /// Fetch the duration for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(duration) = video.duration() { /// println!("{:?}", duration); /// } /// ``` fn duration<'a>(&'a self) -> Option<&'a XsdDuration> where Kind: 'a, { self.object_ref().duration.as_ref() } /// Set the duration for the current object /// /// This overwrites the contents of duration /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdDateTime}; /// # let mut video = Video::default(); /// /// video.set_duration("P3DT1H".parse()?); /// # Ok(()) /// # } /// ``` fn set_duration(&mut self, duration: XsdDuration) -> &mut Self { self.object_mut().duration = Some(duration); self } /// Take the duration from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(duration) = video.take_duration() { /// println!("{:?}", duration); /// } /// ``` fn take_duration(&mut self) -> Option { self.object_mut().duration.take() } /// Delete the duration from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_duration("P1Y2MT3M30S".parse()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.duration().is_some()); /// video.delete_duration(); /// assert!(video.duration().is_none()); /// # Ok(()) /// # } /// ``` fn delete_duration(&mut self) -> &mut Self { self.object_mut().duration = None; self } /// Fetch the published for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(published) = video.published() { /// println!("{:?}", published); /// } /// ``` fn published<'a>(&'a self) -> Option<&'a XsdDateTime> where Kind: 'a, { self.object_ref().published.as_ref() } /// Set the published for the current object /// /// This overwrites the contents of published /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdDateTime}; /// # let mut video = Video::default(); /// /// video.set_published("2020-04-20T04:20:00Z".parse()?); /// # Ok(()) /// # } /// ``` fn set_published(&mut self, published: XsdDateTime) -> &mut Self { self.object_mut().published = Some(published); self } /// Take the published from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(published) = video.take_published() { /// println!("{:?}", published); /// } /// ``` fn take_published(&mut self) -> Option { self.object_mut().published.take() } /// Delete the published from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_published("2020-04-20T04:20:00Z".parse()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.published().is_some()); /// video.delete_published(); /// assert!(video.published().is_none()); /// # Ok(()) /// # } /// ``` fn delete_published(&mut self) -> &mut Self { self.object_mut().published = None; self } /// Fetch the updated for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(updated) = video.updated() { /// println!("{:?}", updated); /// } /// ``` fn updated<'a>(&'a self) -> Option<&'a XsdDateTime> where Kind: 'a, { self.object_ref().updated.as_ref() } /// Set the updated for the current object /// /// This overwrites the contents of updated /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// /// video.set_updated("2020-04-20T04:20:00Z".parse()?); /// # Ok(()) /// # } /// ``` fn set_updated(&mut self, updated: XsdDateTime) -> &mut Self { self.object_mut().updated = Some(updated); self } /// Take the updated from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(updated) = video.take_updated() { /// println!("{:?}", updated); /// } /// ``` fn take_updated(&mut self) -> Option { self.object_mut().updated.take() } /// Delete the updated from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_updated("2020-04-20T04:20:00Z".parse()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.updated().is_some()); /// video.delete_updated(); /// assert!(video.updated().is_none()); /// # Ok(()) /// # } /// ``` fn delete_updated(&mut self) -> &mut Self { self.object_mut().updated = None; self } /// Fetch the in_reply_to for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(in_reply_to) = video.in_reply_to() { /// println!("{:?}", in_reply_to); /// } /// ``` fn in_reply_to<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().in_reply_to.as_ref() } /// Set the in_reply_to for the current object /// /// This overwrites the contents of in_reply_to /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_in_reply_to("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_in_reply_to(&mut self, in_reply_to: T) -> &mut Self where T: Into, { self.object_mut().in_reply_to = Some(in_reply_to.into().into()); self } /// Set many in_reply_tos for the current object /// /// This overwrites the contents of in_reply_to /// /// ```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_in_reply_tos(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_in_reply_tos(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().in_reply_to = Some(v.into()); self } /// Add a in_reply_to to the current object /// /// This does not overwrite the contents of in_reply_to, 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_in_reply_to("https://example.com/one".parse::()?) /// .add_in_reply_to("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_in_reply_to(&mut self, in_reply_to: T) -> &mut Self where T: Into, { let a = match self.object_mut().in_reply_to.take() { Some(mut a) => { a.add(in_reply_to.into()); a } None => vec![in_reply_to.into()].into(), }; self.object_mut().in_reply_to = Some(a); self } /// Take the in_reply_to from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(in_reply_to) = video.take_in_reply_to() { /// println!("{:?}", in_reply_to); /// } /// ``` fn take_in_reply_to(&mut self) -> Option> { self.object_mut().in_reply_to.take() } /// Delete the in_reply_to from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_in_reply_to("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.in_reply_to().is_some()); /// video.delete_in_reply_to(); /// assert!(video.in_reply_to().is_none()); /// # Ok(()) /// # } /// ``` fn delete_in_reply_to(&mut self) -> &mut Self { self.object_mut().in_reply_to = None; self } /// Fetch the replies for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(replies) = video.replies() { /// println!("{:?}", replies); /// } /// ``` fn replies<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().replies.as_ref() } /// Set the replies for the current object /// /// This overwrites the contents of replies /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_replies("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_replies(&mut self, replies: T) -> &mut Self where T: Into, { self.object_mut().replies = Some(replies.into().into()); self } /// Set many replies for the current object /// /// This overwrites the contents of replies /// /// ```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_replies(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_replies(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().replies = Some(v.into()); self } /// Add a replies to the current object /// /// This does not overwrite the contents of replies, 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_replies("https://example.com/one".parse::()?) /// .add_replies("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_replies(&mut self, replies: T) -> &mut Self where T: Into, { let a = match self.object_mut().replies.take() { Some(mut a) => { a.add(replies.into()); a } None => vec![replies.into()].into(), }; self.object_mut().replies = Some(a); self } /// Take the replies from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(replies) = video.take_replies() { /// println!("{:?}", replies); /// } /// ``` fn take_replies(&mut self) -> Option> { self.object_mut().replies.take() } /// Delete the replies from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_replies("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.replies().is_some()); /// video.delete_replies(); /// assert!(video.replies().is_none()); /// # Ok(()) /// # } /// ``` fn delete_replies(&mut self) -> &mut Self { self.object_mut().replies = None; self } /// Fetch the to for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(to) = video.to() { /// println!("{:?}", to); /// } /// ``` fn to<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().to.as_ref() } /// Set the to for the current object /// /// This overwrites the contents of to /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_to("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_to(&mut self, to: T) -> &mut Self where T: Into, { self.object_mut().to = Some(to.into().into()); self } /// Set many tos for the current object /// /// This overwrites the contents of to /// /// ```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_tos(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_tos(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().to = Some(v.into()); self } /// Add a to to the current object /// /// This does not overwrite the contents of to, 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_to("https://example.com/one".parse::()?) /// .add_to("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_to(&mut self, to: T) -> &mut Self where T: Into, { let a = match self.object_mut().to.take() { Some(mut a) => { a.add(to.into()); a } None => vec![to.into()].into(), }; self.object_mut().to = Some(a); self } /// Take the to from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(to) = video.take_to() { /// println!("{:?}", to); /// } /// ``` fn take_to(&mut self) -> Option> { self.object_mut().to.take() } /// Delete the to from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_to("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.to().is_some()); /// video.delete_to(); /// assert!(video.to().is_none()); /// # Ok(()) /// # } /// ``` fn delete_to(&mut self) -> &mut Self { self.object_mut().to = None; self } /// Fetch the bto for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(bto) = video.bto() { /// println!("{:?}", bto); /// } /// ``` fn bto<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().bto.as_ref() } /// Set the bto for the current object /// /// This overwrites the contents of bto /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_bto("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_bto(&mut self, bto: T) -> &mut Self where T: Into, { self.object_mut().bto = Some(bto.into().into()); self } /// Set many btos for the current object /// /// This overwrites the contents of bto /// /// ```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_btos(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_btos(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().bto = Some(v.into()); self } /// Add a bto to the current object /// /// This does not overwrite the contents of bto, 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_bto("https://example.com/one".parse::()?) /// .add_bto("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_bto(&mut self, bto: T) -> &mut Self where T: Into, { let a = match self.object_mut().bto.take() { Some(mut a) => { a.add(bto.into()); a } None => vec![bto.into()].into(), }; self.object_mut().bto = Some(a); self } /// Take the bto from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(bto) = video.take_bto() { /// println!("{:?}", bto); /// } /// ``` fn take_bto(&mut self) -> Option> { self.object_mut().bto.take() } /// Delete the bto from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_bto("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.bto().is_some()); /// video.delete_bto(); /// assert!(video.bto().is_none()); /// # Ok(()) /// # } /// ``` fn delete_bto(&mut self) -> &mut Self { self.object_mut().bto = None; self } /// Fetch the cc for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(cc) = video.cc() { /// println!("{:?}", cc); /// } /// ``` fn cc<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().cc.as_ref() } /// Set the cc for the current object /// /// This overwrites the contents of cc /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_cc("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_cc(&mut self, cc: T) -> &mut Self where T: Into, { self.object_mut().cc = Some(cc.into().into()); self } /// Set many ccs for the current object /// /// This overwrites the contents of cc /// /// ```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_ccs(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_ccs(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().cc = Some(v.into()); self } /// Add a cc to the current object /// /// This does not overwrite the contents of cc, 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_cc("https://example.com/one".parse::()?) /// .add_cc("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_cc(&mut self, cc: T) -> &mut Self where T: Into, { let a = match self.object_mut().cc.take() { Some(mut a) => { a.add(cc.into()); a } None => vec![cc.into()].into(), }; self.object_mut().cc = Some(a); self } /// Take the cc from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(cc) = video.take_cc() { /// println!("{:?}", cc); /// } /// ``` fn take_cc(&mut self) -> Option> { self.object_mut().cc.take() } /// Delete the cc from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_cc("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.cc().is_some()); /// video.delete_cc(); /// assert!(video.cc().is_none()); /// # Ok(()) /// # } /// ``` fn delete_cc(&mut self) -> &mut Self { self.object_mut().cc = None; self } /// Fetch the bcc for the current object /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(bcc) = video.bcc() { /// println!("{:?}", bcc); /// } /// ``` fn bcc<'a>(&'a self) -> Option<&'a OneOrMany> where Kind: 'a, { self.object_ref().bcc.as_ref() } /// Set the bcc for the current object /// /// This overwrites the contents of bcc /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams_new::prelude::*; /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// /// video.set_bcc("https://example.com".parse::()?); /// # Ok(()) /// # } /// ``` fn set_bcc(&mut self, bcc: T) -> &mut Self where T: Into, { self.object_mut().bcc = Some(bcc.into().into()); self } /// Set many bcc for the current object /// /// This overwrites the contents of bcc /// /// ```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_bcc(vec![ /// "https://example.com/one".parse::()?, /// "https://example.com/two".parse()?, /// ]); /// # Ok(()) /// # } /// ``` fn set_many_bcc(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.object_mut().bcc = Some(v.into()); self } /// Add a bcc to the current object /// /// This does not overwrite the contents of bcc, 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_bcc("https://example.com/one".parse::()?) /// .add_bcc("https://example.com/two".parse::()?); /// # Ok(()) /// # } /// ``` fn add_bcc(&mut self, bcc: T) -> &mut Self where T: Into, { let a = match self.object_mut().bcc.take() { Some(mut a) => { a.add(bcc.into()); a } None => vec![bcc.into()].into(), }; self.object_mut().bcc = Some(a); self } /// Take the bcc from the current object, leaving nothing /// /// ```rust /// # use activitystreams_new::object::Video; /// # let mut video = Video::default(); /// # /// use activitystreams_new::prelude::*; /// /// if let Some(bcc) = video.take_bcc() { /// println!("{:?}", bcc); /// } /// ``` fn take_bcc(&mut self) -> Option> { self.object_mut().bcc.take() } /// Delete the bcc from the current object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams_new::{object::Video, primitives::XsdAnyUri}; /// # let mut video = Video::default(); /// # video.set_bcc("https://example.com".parse::()?); /// # /// use activitystreams_new::prelude::*; /// /// assert!(video.bcc().is_some()); /// video.delete_bcc(); /// assert!(video.bcc().is_none()); /// # Ok(()) /// # } /// ``` fn delete_bcc(&mut self) -> &mut Self { self.object_mut().bcc = None; self } } /// Helper methods for interacting with ActivityPub Object types /// /// This trait represents methods valid for any ActivityPub Object. /// /// Documentation for the fields related to these methods can be found on the `ApObject` struct pub trait ApObjectExt: AsApObject { /// Fetch the shares for the current object /// /// ```rust /// # use activitystreams_new::{object::{ApObject, Video}, primitives::XsdString}; /// # let mut video = ApObject::