//! Types and traits for dealing with Activity attributes //! //! ```rust //! # fn main() -> Result<(), anyhow::Error> { //! use activitystreams::{ //! activity::Create, //! context, //! prelude::*, //! iri, //! }; //! //! let mut create = Create::new( //! iri!("https://example.com/actors/abcd"), //! iri!("https://example.com/notes/1234"), //! ); //! //! create //! .set_result(iri!("https://example.com/")) //! .set_instrument(iri!("https://example.com/")) //! .set_id(iri!("https://example.com/activities/abcd")) //! .set_context(context()); //! # Ok(()) //! # } //! ``` use crate::{ base::{AnyBase, AsBase, Base, Extends}, checked::CheckError, markers, object::{ApObject, AsObject, Object}, prelude::BaseExt, primitives::{Either, OneOrMany, XsdBoolean, XsdDateTime}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, }; use iri_string::types::IriString; use std::convert::TryFrom; use time::OffsetDateTime; pub use activitystreams_kinds::activity as kind; use self::kind::*; /// Implementation trait for deriving Activity methods for a type /// /// Any type implementing AsObject will automatically gain methods provided by ActivityExt pub trait AsActivity: markers::Activity { type Kind; /// Immutable borrow of `Activity` fn activity_ref(&self) -> &Activity; /// Mutable borrow of `Activity` fn activity_mut(&mut self) -> &mut Activity; } /// Implementation trait for deriving Actor and Object methods for a type /// /// Any type implementing AsActivityActor will automatically gain methods provided by /// `AsActivityActorExt` pub trait AsActivityActor: markers::Activity { type Inner; fn activity_actor_ref(&self) -> &ActivityActor; fn activity_actor_mut(&mut self) -> &mut ActivityActor; } /// Implementation trait for deriving Actor and Object methods for a type /// /// Any type implementing AsActivityObject will automatically gain methods provided by /// `AsActivityObjectExt` pub trait AsActivityObject: markers::Activity { type Inner; fn activity_object_ref(&self) -> &ActivityObject; fn activity_object_mut(&mut self) -> &mut ActivityObject; } /// Implementation trait for deriving Target methods for a type /// /// Any type implementing AsTarget will automatically gain methods provided by `AsTargetExt` pub trait AsTarget: markers::Activity { type Inner; fn target_ref(&self) -> &Target; fn target_mut(&mut self) -> &mut Target; } /// Implementation trait for deriving Origin methods for a type /// /// Any type implementing AsOrigin will automatically gain methods provided by /// `AsOriginExt` pub trait AsOrigin: markers::Activity { type Inner; fn origin_ref(&self) -> &Origin; fn origin_mut(&mut self) -> &mut Origin; } /// Implementation trait for deriving Target methods for a type /// /// Any type implementing AsOptTarget will automatically gain methods provided by /// `AsOptTargetExt` pub trait AsOptTarget: markers::Activity { type Inner; fn opt_target_ref(&self) -> &OptTarget; fn opt_target_mut(&mut self) -> &mut OptTarget; } /// Implementation trait for deriving Origin methods for a type /// /// Any type implementing AsOptOrigin will automatically gain methods provided by /// `AsOptOriginExt` pub trait AsOptOrigin: markers::Activity { type Inner; fn opt_origin_ref(&self) -> &OptOrigin; fn opt_origin_mut(&mut self) -> &mut OptOrigin; } /// Implementation trait for deriving Question methods for a type /// /// Any type implementing AsQuestion will automatically gain methods provided by /// `QuestionExt` pub trait AsQuestion: markers::Activity { /// Immutable borrow of Question fn question_ref(&self) -> &Question; /// Mutable borrow of Question fn question_mut(&mut self) -> &mut Question; } /// Helper methods for interacting with Activity types /// /// This trait represents methods valid for any ActivityStreams Activity /// /// Documentation for the fields related to these methods can be found on the `Activity` /// struct pub trait ActivityExt: AsActivity { /// Fetch the result for the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(result) = question.result() { /// println!("{:?}", result); /// } /// ``` fn result<'a>(&'a self) -> Option<&'a OneOrMany> where Self::Kind: 'a, { self.activity_ref().result.as_ref() } /// Set the result for the current activity /// /// This overwrites the contents of result /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_result(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_result(&mut self, result: T) -> &mut Self where T: Into, { self.activity_mut().result = Some(result.into().into()); self } /// Set many results for the current activity /// /// This overwrites the contents of result /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_many_results(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_results(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.activity_mut().result = Some(v.into()); self } /// Add a result to the current activity /// /// This does not overwrite the contents of result, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::{prelude::*, iri}; /// # use activitystreams::{activity::Question}; /// # let mut question = Question::new(); /// /// question /// .add_result(iri!("https://example.com/one")) /// .add_result(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_result(&mut self, result: T) -> &mut Self where T: Into, { let c = match self.activity_mut().result.take() { Some(mut c) => { c.add(result.into()); c } None => vec![result.into()].into(), }; self.activity_mut().result = Some(c); self } /// Take the result from the current activity, leaving nothing /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(result) = question.take_result() { /// println!("{:?}", result); /// } /// ``` fn take_result(&mut self) -> Option> { self.activity_mut().result.take() } /// Delete the result from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// # question.set_result(iri!("https://example.com")); /// # /// use activitystreams::prelude::*; /// /// assert!(question.result().is_some()); /// question.delete_result(); /// assert!(question.result().is_none()); /// # Ok(()) /// # } /// ``` fn delete_result(&mut self) -> &mut Self { self.activity_mut().result = None; self } /// Fetch the instrument for the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(instrument) = question.instrument() { /// println!("{:?}", instrument); /// } /// ``` fn instrument<'a>(&'a self) -> Option<&'a OneOrMany> where Self::Kind: 'a, { self.activity_ref().instrument.as_ref() } /// Set the instrument for the current activity /// /// This overwrites the contents of instrument /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_instrument(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_instrument(&mut self, instrument: T) -> &mut Self where T: Into, { self.activity_mut().instrument = Some(instrument.into().into()); self } /// Set many instruments for the current activity /// /// This overwrites the contents of instrument /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_many_instruments(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_instruments(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.activity_mut().instrument = Some(v.into()); self } /// Add a instrument to the current activity /// /// This does not overwrite the contents of instrument, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question /// .add_instrument(iri!("https://example.com/one")) /// .add_instrument(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_instrument(&mut self, instrument: T) -> &mut Self where T: Into, { let c = match self.activity_mut().instrument.take() { Some(mut c) => { c.add(instrument.into()); c } None => vec![instrument.into()].into(), }; self.activity_mut().instrument = Some(c); self } /// Take the instrument from the current activity, leaving nothing /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(instrument) = question.take_instrument() { /// println!("{:?}", instrument); /// } /// ``` fn take_instrument(&mut self) -> Option> { self.activity_mut().instrument.take() } /// Delete the instrument from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// # question.set_instrument(iri!("https://example.com")); /// # /// use activitystreams::prelude::*; /// /// assert!(question.instrument().is_some()); /// question.delete_instrument(); /// assert!(question.instrument().is_none()); /// # Ok(()) /// # } /// ``` fn delete_instrument(&mut self) -> &mut Self { self.activity_mut().instrument = None; self } } /// Helper methods for interacting with Activity types with actor and object fields /// /// Documentation for the fields related to these methods can be found on the /// `ActorAndObject` struct pub trait AsActivityActorExt: AsActivityActor { /// Fetch the actor for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Create}; /// # let mut create = Create::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// let actor_ref = create.actor(); /// println!("{:?}", actor_ref); /// ``` fn actor(&self) -> Result<&OneOrMany, CheckError> where Self: BaseExt, { let actor = self.actor_unchecked(); for any_base in actor { let id = any_base.id().ok_or(CheckError(None))?; self.check_authority(id)?; } Ok(actor) } /// Fetch the actor for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Create}; /// # let mut create = Create::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// let actor_ref = create.actor_unchecked(); /// println!("{:?}", actor_ref); /// ``` fn actor_unchecked(&self) -> &OneOrMany { &self.activity_actor_ref().actor } /// Check if the actor's ID is `id` /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// use activitystreams::prelude::*; /// /// create.set_actor(iri!("https://example.com")); /// /// assert!(create.actor_is(&iri!("https://example.com"))); /// # Ok(()) /// # } /// ``` fn actor_is(&self, id: &IriString) -> bool { self.actor_unchecked().is_single_id(id) } /// Set the actor for the current activity /// /// This overwrites the contents of actor /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create.set_actor(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_actor(&mut self, actor: T) -> &mut Self where T: Into, { self.activity_actor_mut().actor = actor.into().into(); self } /// Set many actors for the current activity /// /// This overwrites the contents of actor /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create.set_many_actors(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_actors(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.activity_actor_mut().actor = v.into(); self } /// Add a actor to the current activity /// /// This does not overwrite the contents of actor, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create /// .add_actor(iri!("https://example.com/one")) /// .add_actor(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_actor(&mut self, actor: T) -> &mut Self where T: Into, { self.activity_actor_mut().actor.add(actor.into()); self } } pub trait AsActivityObjectExt: AsActivityObject { /// Fetch the object for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Create}; /// # let mut create = Create::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// let object_ref = create.object(); /// println!("{:?}", object_ref); /// ``` fn object(&self) -> Result<&OneOrMany, CheckError> where Self: BaseExt, { let object = self.object_unchecked(); for any_base in object { let id = any_base.id().ok_or(CheckError(None))?; self.check_authority(id)?; } Ok(object) } /// Fetch the object for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Create}; /// # let mut create = Create::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// let object_ref = create.object_unchecked(); /// println!("{:?}", object_ref); /// ``` fn object_unchecked(&self) -> &OneOrMany { &self.activity_object_ref().object } /// Check if the object's ID is `id` /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// use activitystreams::prelude::*; /// /// create.set_object(iri!("https://example.com")); /// /// assert!(create.object_is(&iri!("https://example.com"))); /// # Ok(()) /// # } /// ``` fn object_is(&self, id: &IriString) -> bool { self.object_unchecked().is_single_id(id) } /// Set the object for the current activity /// /// This overwrites the contents of object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create.set_object(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_object(&mut self, object: T) -> &mut Self where T: Into, { self.activity_object_mut().object = object.into().into(); self } /// Set many objects for the current activity /// /// This overwrites the contents of object /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create.set_many_objects(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_objects(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.activity_object_mut().object = v.into(); self } /// Add a object to the current activity /// /// This does not overwrite the contents of object, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Create, iri}; /// # let mut create = Create::new(context(), context()); /// /// create /// .add_object(iri!("https://example.com/one")) /// .add_object(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_object(&mut self, object: T) -> &mut Self where T: Into, { self.activity_object_mut().object.add(object.into()); self } } /// Helper methods for interacting with Activity types with a target field /// /// Documentation for the target field can be found on the `Invite` struct pub trait AsTargetExt: AsTarget { /// Fetch the target for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Invite}; /// # let mut invite = Invite::new(context(), context(), context()); /// # /// use activitystreams::prelude::*; /// /// let target_ref = invite.target(); /// println!("{:?}", target_ref); /// ``` fn target(&self) -> &OneOrMany { &self.target_ref().target } /// Set the target for the current activity /// /// This overwrites the contents of target /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Invite, iri}; /// # let mut invite = Invite::new(context(), context(), context()); /// /// invite.set_target(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_target(&mut self, target: T) -> &mut Self where T: Into, { self.target_mut().target = target.into().into(); self } /// Set many targets for the current activity /// /// This overwrites the contents of target /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Invite, iri}; /// # let mut invite = Invite::new(context(), context(), context()); /// /// invite.set_many_targets(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_targets(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.target_mut().target = v.into(); self } /// Add a target to the current activity /// /// This does not overwrite the contents of target, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Invite, iri}; /// # let mut invite = Invite::new(context(), context(), context()); /// /// invite /// .add_target(iri!("https://example.com/one")) /// .add_target(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_target(&mut self, target: T) -> &mut Self where T: Into, { self.target_mut().target.add(target.into()); self } } /// Helper methods for interacting with Activity types with an origin /// /// Documentation for the origin field can be found on the `Arrive` struct pub trait AsOriginExt: AsOrigin { /// Fetch the origin for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Arrive}; /// # let mut arrive = Arrive::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// let origin_ref = arrive.origin(); /// println!("{:?}", origin_ref); /// ``` fn origin(&self) -> &OneOrMany { &self.origin_ref().origin } /// Set the origin for the current activity /// /// This overwrites the contents of origin /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Arrive, iri}; /// # let mut arrive = Arrive::new(context(), context()); /// /// arrive.set_origin(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_origin(&mut self, origin: T) -> &mut Self where T: Into, { self.origin_mut().origin = origin.into().into(); self } /// Set many origins for the current activity /// /// This overwrites the contents of origin /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Arrive, iri}; /// # let mut arrive = Arrive::new(context(), context()); /// /// arrive.set_many_origins(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_origins(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.origin_mut().origin = v.into(); self } /// Add a origin to the current activity /// /// This does not overwrite the contents of origin, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Arrive, iri}; /// # let mut arrive = Arrive::new(context(), context()); /// /// arrive /// .add_origin(iri!("https://example.com/one")) /// .add_origin(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_origin(&mut self, origin: T) -> &mut Self where T: Into, { self.origin_mut().origin.add(origin.into()); self } } /// Helper methods for interacting with Activity types with an optional target field /// /// Documentation for the target field can be found on the /// `OptTarget` struct pub trait AsOptTargetExt: AsOptTarget { /// Fetch the target for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Announce}; /// # let mut announce = Announce::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// if let Some(target_ref) = announce.target() { /// println!("{:?}", target_ref); /// } /// ``` fn target(&self) -> Option<&OneOrMany> { self.opt_target_ref().target.as_ref() } /// Set the target for the current activity /// /// This overwrites the contents of target /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Announce, iri}; /// # let mut announce = Announce::new(context(), context()); /// /// announce.set_target(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_target(&mut self, target: T) -> &mut Self where T: Into, { self.opt_target_mut().target = Some(target.into().into()); self } /// Set many targets for the current activity /// /// This overwrites the contents of target /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Announce, iri}; /// # let mut announce = Announce::new(context(), context()); /// /// announce.set_many_targets(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_targets(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.opt_target_mut().target = Some(v.into()); self } /// Add a target to the current activity /// /// This does not overwrite the contents of target, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Announce, iri}; /// # let mut announce = Announce::new(context(), context()); /// /// announce /// .add_target(iri!("https://example.com/one")) /// .add_target(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_target(&mut self, target: T) -> &mut Self where T: Into, { let c = match self.opt_target_mut().target.take() { Some(mut c) => { c.add(target.into()); c } None => vec![target.into()].into(), }; self.opt_target_mut().target = Some(c); self } /// Take a target from the current activity, leaving nothing /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{ /// # context, /// # activity::Announce, /// # }; /// # let mut announce = Announce::new(context(), context()); /// /// if let Some(target) = announce.take_target() { /// println!("{:?}", target); /// } /// # Ok(()) /// # } /// ``` fn take_target(&mut self) -> Option> { self.opt_target_mut().target.take() } /// Delete a target from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{ /// # context, /// # activity::Announce, /// # }; /// # let mut announce = Announce::new(context(), context()); /// # announce.set_target(context()); /// /// assert!(announce.target().is_some()); /// announce.delete_target(); /// assert!(announce.target().is_none()); /// # Ok(()) /// # } /// ``` fn delete_target(&mut self) -> &mut Self { self.opt_target_mut().target = None; self } } /// Helper methods for interacting with Activity types with an optional origin field /// /// Documentation for the origin field can be found on the /// `Delete` struct pub trait AsOptOriginExt: AsOptOrigin { /// Fetch the origin for the current activity /// /// ```rust /// # use activitystreams::{context, activity::Delete}; /// # let mut delete = Delete::new(context(), context()); /// # /// use activitystreams::prelude::*; /// /// if let Some(origin_ref) = delete.origin() { /// println!("{:?}", origin_ref); /// } /// ``` fn origin(&self) -> Option<&OneOrMany> { self.opt_origin_ref().origin.as_ref() } /// Set the origin for the current activity /// /// This overwrites the contents of origin /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Delete, iri}; /// # let mut delete = Delete::new(context(), context()); /// /// delete.set_origin(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_origin(&mut self, origin: T) -> &mut Self where T: Into, { self.opt_origin_mut().origin = Some(origin.into().into()); self } /// Set many origins for the current activity /// /// This overwrites the contents of origin /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Delete, iri}; /// # let mut delete = Delete::new(context(), context()); /// /// delete.set_many_origins(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_origins(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.opt_origin_mut().origin = Some(v.into()); self } /// Add a origin to the current activity /// /// This does not overwrite the contents of origin, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Delete, iri}; /// # let mut delete = Delete::new(context(), context()); /// /// delete /// .add_origin(iri!("https://example.com/one")) /// .add_origin(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_origin(&mut self, origin: T) -> &mut Self where T: Into, { let c = match self.opt_origin_mut().origin.take() { Some(mut c) => { c.add(origin.into()); c } None => vec![origin.into()].into(), }; self.opt_origin_mut().origin = Some(c); self } /// Take a origin from the current activity, leaving nothing /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Delete}; /// # let mut delete = Delete::new(context(), context()); /// /// if let Some(origin) = delete.take_origin() { /// println!("{:?}", origin); /// } /// # Ok(()) /// # } /// ``` fn take_origin(&mut self) -> Option> { self.opt_origin_mut().origin.take() } /// Delete a origin from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{context, activity::Delete}; /// # let mut delete = Delete::new(context(), context()); /// # delete.set_origin(context()); /// /// assert!(delete.origin().is_some()); /// delete.delete_origin(); /// assert!(delete.origin().is_none()); /// # Ok(()) /// # } /// ``` fn delete_origin(&mut self) -> &mut Self { self.opt_origin_mut().origin = None; self } } /// Helper methods for interacting with Question types /// /// This trait represents methods valid for an ActivityStreams Question /// /// Documentation for the fields related to these methods can be found on the `Question` /// struct pub trait QuestionExt: AsQuestion { /// Fetch the one_of field for the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(one_of) = question.one_of() { /// println!("{:?}", one_of); /// } /// ``` fn one_of(&self) -> Option<&OneOrMany> { self.question_ref().one_of.as_ref() } /// Set the one_of field for the current activity /// /// This overwrites the contents of one_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_one_of(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_one_of(&mut self, one_of: T) -> &mut Self where T: Into, { self.question_mut().one_of = Some(one_of.into().into()); self } /// Set many one_of items for the current activity /// /// This overwrites the contents of one_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_many_one_ofs(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_one_ofs(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.question_mut().one_of = Some(v.into()); self } /// Add a one_of to the current activity /// /// This does not overwrite the contents of one_of, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question /// .add_one_of(iri!("https://example.com/one")) /// .add_one_of(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_one_of(&mut self, one_of: T) -> &mut Self where T: Into, { let v = match self.question_mut().one_of.take() { Some(mut v) => { v.add(one_of.into()); v } None => vec![one_of.into()].into(), }; self.question_mut().one_of = Some(v); self } /// Take the one_of field from the current activity, leaving nothing /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(one_of) = question.take_one_of() { /// println!("{:?}", one_of); /// } /// ``` fn take_one_of(&mut self) -> Option> { self.question_mut().one_of.take() } /// Delete the one_of field from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// # question.set_one_of(iri!("https://example.com")); /// # /// use activitystreams::prelude::*; /// /// assert!(question.one_of().is_some()); /// question.delete_one_of(); /// assert!(question.one_of().is_none()); /// # Ok(()) /// # } /// ``` fn delete_one_of(&mut self) -> &mut Self { self.question_mut().one_of = None; self } /// Fetch the any_of field for the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(any_of) = question.any_of() { /// println!("{:?}", any_of); /// } /// ``` fn any_of(&self) -> Option<&OneOrMany> { self.question_ref().any_of.as_ref() } /// Set the any_of field for the current activity /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_any_of(iri!("https://example.com")); /// # Ok(()) /// # } /// ``` fn set_any_of(&mut self, any_of: T) -> &mut Self where T: Into, { self.question_mut().any_of = Some(any_of.into().into()); self } /// Set many any_of items for the current activity /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_many_any_ofs(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_any_ofs(&mut self, items: I) -> &mut Self where I: IntoIterator, T: Into, { let v: Vec<_> = items.into_iter().map(Into::into).collect(); self.question_mut().any_of = Some(v.into()); self } /// Add an any_of to the current activity /// /// This does not overwrite the contents of any_of, only appends an item /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question /// .add_any_of(iri!("https://example.com/one")) /// .add_any_of(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_any_of(&mut self, any_of: T) -> &mut Self where T: Into, { let v = match self.question_mut().any_of.take() { Some(mut v) => { v.add(any_of.into()); v } None => vec![any_of.into()].into(), }; self.question_mut().any_of = Some(v); self } /// Take the any_of field from the current activity, leaving nothing /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(any_of) = question.take_any_of() { /// println!("{:?}", any_of); /// } /// ``` fn take_any_of(&mut self) -> Option> { self.question_mut().any_of.take() } /// Delete the any_of field from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// # question.set_any_of(iri!("https://example.com")); /// # /// use activitystreams::prelude::*; /// /// assert!(question.any_of().is_some()); /// question.delete_any_of(); /// assert!(question.any_of().is_none()); /// # Ok(()) /// # } /// ``` fn delete_any_of(&mut self) -> &mut Self { self.question_mut().any_of = None; self } /// Fetch the closed field for the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(closed) = question.closed() { /// println!("{:?}", closed); /// } /// ``` fn closed(&self) -> Option, Either>> { self.question_ref().closed.as_ref().map(|either| { either .as_ref() .map_right(|r| r.as_ref().map_left(|l| *l.as_datetime()).map_right(|r| r.0)) }) } /// Set the closed field for the current activity /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_closed_base(iri!("https://example.com/one")); /// # Ok(()) /// # } /// ``` fn set_closed_base(&mut self, closed: T) -> &mut Self where T: Into, { self.question_mut().closed = Some(Either::Left(OneOrMany::from_one(closed.into()))); self } /// Set many closed items for the current activity /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_many_closed_bases(vec![ /// iri!("https://example.com/one"), /// iri!("https://example.com/two"), /// ]); /// # Ok(()) /// # } /// ``` fn set_many_closed_bases(&mut self, closed: I) -> &mut Self where I: IntoIterator, T: Into, { let many = OneOrMany::from_many(closed.into_iter().map(|t| t.into()).collect()); self.question_mut().closed = Some(Either::Left(many)); self } /// Set the closed field as a date /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_closed_date(time::OffsetDateTime::now_utc()); /// # Ok(()) /// # } /// ``` fn set_closed_date(&mut self, closed: OffsetDateTime) -> &mut Self { self.question_mut().closed = Some(Either::Right(Either::Left(closed.into()))); self } /// Set the closed field as a boolean /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question.set_closed_bool(true); /// # Ok(()) /// # } /// ``` fn set_closed_bool(&mut self, closed: bool) -> &mut Self { self.question_mut().closed = Some(Either::Right(Either::Right(closed.into()))); self } /// Add an object or link to the closed field /// /// This overwrites the contents of any_of /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::prelude::*; /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// /// question /// .add_closed_base(iri!("https://example.com/one")) /// .add_closed_base(iri!("https://example.com/two")); /// # Ok(()) /// # } /// ``` fn add_closed_base(&mut self, closed: T) -> &mut Self where T: Into, { let one_or_many = match self.question_mut().closed.take() { Some(Either::Left(mut one_or_many)) => { one_or_many.add(closed.into()); one_or_many } _ => OneOrMany::from_one(closed.into()), }; self.question_mut().closed = Some(Either::Left(one_or_many)); self } /// Take the closed field from the current activity /// /// ```rust /// # use activitystreams::activity::Question; /// # let mut question = Question::new(); /// # /// use activitystreams::prelude::*; /// /// if let Some(closed) = question.take_closed() { /// println!("{:?}", closed); /// } /// ``` fn take_closed(&mut self) -> Option, Either>> { self.question_mut() .closed .take() .map(|either| either.map_right(|r| r.map(|date| date.into(), |b| b.into()))) } /// Remove the closed field from the current activity /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// # use activitystreams::{activity::Question, iri}; /// # let mut question = Question::new(); /// # question.set_closed_bool(true); /// # /// use activitystreams::prelude::*; /// /// assert!(question.closed().is_some()); /// question.delete_closed(); /// assert!(question.closed().is_none()); /// # Ok(()) /// # } /// ``` fn delete_closed(&mut self) -> &mut Self { self.question_mut().closed = None; self } } /// Indicates that the actor accepts the object. /// /// The target property can be used in certain circumstances to indicate the context into which the /// object has been accepted. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Accept that aren't already present on an ActorAndObject. pub type Accept = ActorAndObject; /// Indicates that the actor has added the object to the target. /// /// If the target property is not explicitly specified, the target would need to be determined /// implicitly by context. The origin can be used to identify the context from which the object originated. /// /// This is just an alias for `ActorAndObjectOptOriginAndTarget` because there's no fields inherent to /// Add that aren't already present on an OptOrigin. pub type Add = ActorAndObjectOptOriginAndTarget; /// Indicates that the actor is blocking the object. /// /// Blocking is a stronger form of Ignore. The typical use is to support social systems that allow /// one user to block activities or content of other users. The target and origin typically have no /// defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Block that aren't already present on an ActorAndObject. pub type Block = ActorAndObject; /// Indicates that the actor has created the object. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Create that aren't already present on an ActorAndObject. pub type Create = ActorAndObject; /// Indicates that the actor dislikes the object. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Dislike that aren't already present on an ActorAndObject. pub type Dislike = ActorAndObject; /// Indicates that the actor is "flagging" the object. /// /// Flagging is defined in the sense common to many social platforms as reporting content as being /// inappropriate for any number of reasons. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Flag that aren't already present on an ActorAndObject. pub type Flag = ActorAndObject; /// Indicates that the actor is "following" the object. /// /// Following is defined in the sense typically used within Social systems in which the actor is /// interested in any activity performed by or on the object. The target and origin typically have /// no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Follow /// that aren't already present on an ActorAndObject. pub type Follow = ActorAndObject; /// Indicates that the actor is ignoring the object. /// /// The target and origin typically have no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Ignore /// that aren't already present on an ActorAndObject. pub type Ignore = ActorAndObject; /// Indicates that the actor has joined the object. /// /// The target and origin typically have no defined meaning /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Join that /// aren't already present on an ActorAndObject. pub type Join = ActorAndObject; /// Indicates that the actor has left the object. /// /// The target and origin typically have no meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Leave that /// aren't already present on an ActorAndObject. pub type Leave = ActorAndObject; /// Indicates that the actor likes, recommends or endorses the object. /// /// The target and origin typically have no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Like that /// aren't already present on an ActorAndObject. pub type Like = ActorAndObject; /// Indicates that the actor has listened to the object. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Listen /// that aren't already present on an ActorAndObject. pub type Listen = ActorAndObject; /// Indicates that the actor has read the object. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Read that /// aren't already present on an ActorAndObject. pub type Read = ActorAndObject; /// Indicates that the actor is rejecting the object. /// /// The target and origin typically have no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to Reject /// that aren't already present on an ActorAndObject. pub type Reject = ActorAndObject; /// A specialization of Accept indicating that the acceptance is tentative. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// TentativeAccept that aren't already present on an ActorAndObject. pub type TentativeAccept = ActorAndObject; /// A specialization of Reject in which the rejection is considered tentative. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// TentativeReject that aren't already present on an ActorAndObject. pub type TentativeReject = ActorAndObject; /// Indicates that the actor is undoing the object. /// /// In most cases, the object will be an Activity describing some previously performed action (for /// instance, a person may have previously "liked" an article but, for whatever reason, might /// choose to undo that like at some later point in time). /// /// The target and origin typically have no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Undo that aren't already present on an ActorAndObject. pub type Undo = ActorAndObject; /// Indicates that the actor has updated the object. /// /// Note, however, that this vocabulary does not define a mechanism for describing the actual set /// of modifications made to object. /// /// The target and origin typically have no defined meaning. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Update that aren't already present on an ActorAndObject. pub type Update = ActorAndObject; /// Indicates that the actor has viewed the object. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// View that aren't already present on an ActorAndObject. pub type View = ActorAndObject; /// Indicates that the actor is calling the target's attention the object. /// /// The origin typically has no defined meaning. /// /// This is just an alias for `ActorAndObjectOptTarget` because there's no fields inherent to /// Announce that aren't already present on an OptTarget. pub type Announce = ActorAndObjectOptTarget; /// Indicates that the actor is offering the object. /// /// If specified, the target indicates the entity to which the object is being offered. /// /// This is just an alias for `ActorAndObjectOptTarget` because there's no fields inherent to /// Offer that aren't already present on an OptTarget. pub type Offer = ActorAndObjectOptTarget; /// Indicates that the actor has moved object from origin to target. /// /// If the origin or target are not specified, either can be determined by context. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Move that aren't already present on an OptOrigin. pub type Move = ActorAndObjectOptOrigin; /// Indicates that the actor is removing the object. /// /// If specified, the origin indicates the context from which the object is being removed. /// /// This is just an alias for `ActorAndObject` because there's no fields inherent to /// Remove that aren't already present on an OptOrigin. pub type Remove = ActorAndObjectOptOrigin; /// An IntransitiveActivity that indicates that the actor has arrived at the location. /// /// The origin can be used to identify the context from which the actor originated. The target /// typically has no defined meaning. pub type Arrive = ActorAndOrigin; /// A specialization of Offer in which the actor is extending an invitation for the object to the /// target. pub type Invite = Target>; /// Indicates that the actor has deleted the object. /// /// If specified, the origin indicates the context from which the object was deleted. pub type Delete = ActorAndObjectOptOrigin; /// Indicates that the actor is traveling to target from origin. /// /// Travel is an IntransitiveObject whose actor specifies the direct object. If the target or /// origin are not specified, either can be determined by context. pub type Travel = OptOrigin>>>; /// Represents a question being asked. /// /// Question objects are an extension of IntransitiveActivity. That is, the Question object is an /// Activity, but the direct object is the question itself and therefore it would not contain an /// object property. /// /// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a /// Question object MUST NOT have both properties. #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct Question { /// Identifies an exclusive option for a Question. /// /// Use of one_of implies that the Question can have only a single answer. To indicate that a /// Question can have multiple answers, use any_of. /// /// - Range: Object | Link /// - Functional: false #[serde(skip_serializing_if = "Option::is_none")] one_of: Option>, /// Identifies an inclusive option for a Question. /// /// Use of any_of implies that the Question can have multiple answers. To indicate that a /// Question can have only one answer, use one_of. /// /// - Range: Object | Link /// - Functional: false #[serde(skip_serializing_if = "Option::is_none")] any_of: Option>, /// Indicates that a question has been closed, and answers are no longer accepted. /// /// - Range: Object | Link | xsd:datetime | xsd:boolean /// - Functional: false #[serde(skip_serializing_if = "Option::is_none")] closed: Option, Either>>, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Activity, } /// Activity with actor and object properties pub type ActorAndObject = ActivityActor>>; /// Activity with actor and origin properties pub type ActorAndOrigin = Origin>>; /// Activity with actor and object properties, and optional origin and target properties pub type ActorAndObjectOptOriginAndTarget = OptOrigin>>; /// Activity with actor and object properties, and and optional origin property pub type ActorAndObjectOptOrigin = OptOrigin>; /// Activity with actor and object properties, and and optional target property pub type ActorAndObjectOptTarget = OptTarget>; /// Activity objects are specializations of the base Object type that provide information about /// actions that have either already occurred, are in the process of occurring, or may occur in the /// future. #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct Activity { /// Describes the result of the activity. /// /// For instance, if a particular action results in the creation of a new resource, the result /// property can be used to describe that new resource. /// /// - Range: Object | Link /// - Funcitonal: false #[serde(skip_serializing_if = "Option::is_none")] result: Option>, /// Identifies one or more objects used (or to be used) in the completion of an Activity. /// /// - Range: Object | Link /// - Funcitonal: false #[serde(skip_serializing_if = "Option::is_none")] instrument: Option>, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Object, } /// Activity with an actor property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct ActivityActor { actor: OneOrMany, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } /// Activity with an object property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct ActivityObject { object: OneOrMany, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } /// Activity with an origin property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct Origin { /// Describes an indirect object of the activity from which the activity is directed. /// /// The precise meaning of the origin is the object of the English preposition "from". For /// instance, in the activity "John moved an item to List B from List A", the origin of the /// activity is "List A". /// /// - Range: Object | Link /// - Functional: false origin: OneOrMany, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } /// Activity with an optional origin property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct OptOrigin { /// Describes an indirect object of the activity from which the activity is directed. /// /// The precise meaning of the origin is the object of the English preposition "from". For /// instance, in the activity "John moved an item to List B from List A", the origin of the /// activity is "List A". /// /// - Range: Object | Link /// - Functional: false #[serde(skip_serializing_if = "Option::is_none")] origin: Option>, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } /// Activity with a target property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct Target { /// Describes the indirect object, or target, of the activity. /// /// The precise meaning of the target is largely dependent on the type of action being /// described but will often be the object of the English preposition "to". For instance, in /// the activity "John added a movie to his wishlist", the target of the activity is John's /// wishlist. An activity can have more than one target /// /// - Range: Object | Link /// - Functional: false target: OneOrMany, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } /// Activity with an optional target property #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct OptTarget { /// Describes the indirect object, or target, of the activity. /// /// The precise meaning of the target is largely dependent on the type of action being /// described but will often be the object of the English preposition "to". For instance, in /// the activity "John added a movie to his wishlist", the target of the activity is John's /// wishlist. An activity can have more than one target /// /// - Range: Object | Link /// - Functional: false #[serde(skip_serializing_if = "Option::is_none")] target: Option>, /// base fields and unparsed json ends up here #[serde(flatten)] inner: Inner, } impl Activity { /// Create a new Activity /// /// ```rust /// use activitystreams::activity::Activity; /// /// let activity = Activity::::new(); /// ``` pub fn new() -> Self where Kind: Default, { Activity { result: None, instrument: None, inner: Object::new(), } } /// Create a new activity with `None` for it's `kind` property /// /// This means that no `type` field will be present in serialized JSON /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::activity::Activity; /// /// let activity = Activity::<()>::new_none_type(); /// /// let s = serde_json::to_string(&activity)?; /// /// assert_eq!(s, "{}"); /// # Ok(()) /// # } /// ``` pub fn new_none_type() -> Self { Activity { result: None, instrument: None, inner: Object::new_none_type(), } } fn extending(mut inner: Object) -> Result { let result = inner.remove("result")?; let instrument = inner.remove("instrument")?; Ok(Activity { result, instrument, inner, }) } fn retracting(self) -> Result, serde_json::Error> { let Activity { result, instrument, mut inner, } = self; inner .insert("result", result)? .insert("instrument", instrument)?; Ok(inner) } } impl ActivityActor { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let actor = inner.remove("actor")?; Ok(ActivityActor { actor, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let ActivityActor { actor, mut inner } = self; inner.insert("actor", actor)?; Ok(inner) } } impl ActivityObject { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let object = inner.remove("object")?; Ok(ActivityObject { object, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let ActivityObject { object, mut inner } = self; inner.insert("object", object)?; Ok(inner) } } impl Arrive { pub fn new(actor: T, origin: U) -> Self where T: Into>, U: Into>, { Origin { origin: origin.into(), inner: ActivityActor { actor: actor.into(), inner: Activity::new(), }, } } /// Deconstruct the Arrive into its parts /// /// ```rust /// use activitystreams::activity::Arrive; /// /// let activity = Arrive::new(vec![], vec![]); /// /// let (actor, origin, activity) = activity.into_parts(); /// ``` pub fn into_parts(self) -> (OneOrMany, OneOrMany, Activity) { (self.inner.actor, self.origin, self.inner.inner) } } impl Invite { pub fn new(actor: T, object: U, target: V) -> Self where T: Into>, U: Into>, V: Into>, { Target { target: target.into(), inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new(), }, }, } } /// Deconstruct the Invite into its parts /// /// ```rust /// use activitystreams::activity::Invite; /// /// let activity = Invite::new(vec![], vec![], vec![]); /// /// let (actor, object, target, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( OneOrMany, OneOrMany, OneOrMany, Activity, ) { ( self.inner.actor, self.inner.inner.object, self.target, self.inner.inner.inner, ) } } impl Delete { /// Create a new Delete Activity /// /// ```rust /// use activitystreams::activity::Delete; /// /// let activity = Delete::new(vec![], vec![]); /// ``` pub fn new(actor: T, object: U) -> Self where T: Into>, U: Into>, { OptOrigin { origin: None, inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new(), }, }, } } /// Deconstruct the Delete into its parts /// /// ```rust /// use activitystreams::activity::Delete; /// /// let activity = Delete::new(vec![], vec![]); /// /// let (actor, object, origin, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( OneOrMany, OneOrMany, Option>, Activity, ) { ( self.inner.actor, self.inner.inner.object, self.origin, self.inner.inner.inner, ) } } impl Travel { /// Create a new Travel Activity /// /// ```rust /// use activitystreams::activity::Travel; /// /// let activity = Travel::new(vec![]); /// ``` pub fn new(actor: T) -> Self where T: Into>, { OptOrigin { origin: None, inner: OptTarget { target: None, inner: ActivityActor { actor: actor.into(), inner: Activity::new(), }, }, } } #[allow(clippy::type_complexity)] /// Deconstruct the Travel into its parts /// /// ```rust /// use activitystreams::activity::Travel; /// /// let activity = Travel::new(vec![]); /// /// let (actor, origin, target, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( OneOrMany, Option>, Option>, Activity, ) { ( self.inner.inner.actor, self.origin, self.inner.target, self.inner.inner.inner, ) } } impl ActorAndObject { /// Create a new ActorAndObject Activity /// /// ```rust /// use activitystreams::activity::ActorAndObject; /// /// let activity = ActorAndObject::::new(vec![], vec![]); /// ``` pub fn new(actor: T, object: U) -> Self where T: Into>, U: Into>, Kind: Default, { ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new(), }, } } /// Create a new ActorAndObject with `None` for it's `kind` property /// /// This means that no `type` field will be present in serialized JSON /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::activity::ActorAndObject; /// /// let activity = ActorAndObject::<()>::new_none_type(vec![], vec![]); /// /// let s = serde_json::to_string(&activity)?; /// /// assert_eq!(s, r#"{"actor":[],"object":[]}"#); /// # Ok(()) /// # } /// ``` pub fn new_none_type(actor: T, object: U) -> Self where T: Into>, U: Into>, { ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new_none_type(), }, } } /// Deconstruct the ActorAndObject into its parts /// /// ```rust /// use activitystreams::activity::ActorAndObject; /// /// let activity = ActorAndObject::::new(vec![], vec![]); /// /// let (actor, object, activity) = activity.into_parts(); /// ``` pub fn into_parts(self) -> (OneOrMany, OneOrMany, Activity) { (self.actor, self.inner.object, self.inner.inner) } } impl ActorAndObjectOptTarget { /// Create a new ActorAndObjectOptTarget Activity /// /// ```rust /// use activitystreams::activity::ActorAndObjectOptTarget; /// /// let activity = ActorAndObjectOptTarget::::new( /// vec![], /// vec![] /// ); /// ``` pub fn new(actor: T, object: U) -> Self where T: Into>, U: Into>, Kind: Default, { OptTarget { target: None, inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new(), }, }, } } /// Create a new ActorAndObject with `None` for it's `kind` property /// /// This means that no `type` field will be present in serialized JSON /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::activity::ActorAndObjectOptTarget; /// /// let activity = ActorAndObjectOptTarget::<()>::new_none_type(vec![], vec![]); /// /// let s = serde_json::to_string(&activity)?; /// /// assert_eq!(s, r#"{"actor":[],"object":[]}"#); /// # Ok(()) /// # } /// ``` pub fn new_none_type(actor: T, object: U) -> Self where T: Into>, U: Into>, { OptTarget { target: None, inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new_none_type(), }, }, } } #[allow(clippy::type_complexity)] /// Deconstruct the ActorAndObjectOptTarget into its parts /// /// ```rust /// use activitystreams::activity::ActorAndObjectOptTarget; /// /// let activity = ActorAndObjectOptTarget::::new(vec![], vec![]); /// /// let (actor, object, target, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( OneOrMany, OneOrMany, Option>, Activity, ) { ( self.inner.actor, self.inner.inner.object, self.target, self.inner.inner.inner, ) } } impl ActorAndObjectOptOriginAndTarget { /// Create a new ActorAndObject Activity /// /// ```rust /// use activitystreams::activity::ActorAndObjectOptOriginAndTarget; /// /// let activity = ActorAndObjectOptOriginAndTarget::::new(vec![], vec![]); /// ``` pub fn new(actor: T, object: U) -> Self where T: Into>, U: Into>, Kind: Default, { OptOrigin { origin: None, inner: OptTarget { target: None, inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new(), }, }, }, } } /// Create a new ActorAndObject with `None` for it's `kind` property /// /// This means that no `type` field will be present in serialized JSON /// /// ```rust /// # fn main() -> Result<(), anyhow::Error> { /// use activitystreams::activity::ActorAndObjectOptOriginAndTarget; /// /// let activity = ActorAndObjectOptOriginAndTarget::<()>::new_none_type(vec![], vec![]); /// /// let s = serde_json::to_string(&activity)?; /// /// assert_eq!(s, r#"{"actor":[],"object":[]}"#); /// # Ok(()) /// # } /// ``` pub fn new_none_type(actor: T, object: U) -> Self where T: Into>, U: Into>, { OptOrigin { origin: None, inner: OptTarget { target: None, inner: ActivityActor { actor: actor.into(), inner: ActivityObject { object: object.into(), inner: Activity::new_none_type(), }, }, }, } } #[allow(clippy::type_complexity)] /// Deconstruct the ActorAndObjectOptOriginAndTarget into its parts /// /// ```rust /// use activitystreams::activity::ActorAndObjectOptOriginAndTarget; /// /// let activity = ActorAndObjectOptOriginAndTarget::::new(vec![], vec![]); /// /// let (actor, object, origin, target, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( OneOrMany, OneOrMany, Option>, Option>, Activity, ) { ( self.inner.inner.actor, self.inner.inner.inner.object, self.origin, self.inner.target, self.inner.inner.inner.inner, ) } } impl Origin { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let origin = inner.remove("origin")?; Ok(Origin { origin, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let Origin { origin, mut inner } = self; inner.insert("origin", origin)?; Ok(inner) } } impl OptOrigin { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let origin = inner.remove("origin")?; Ok(OptOrigin { origin, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let OptOrigin { origin, mut inner } = self; inner.insert("origin", origin)?; Ok(inner) } } impl Target { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let target = inner.remove("target")?; Ok(Target { target, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let Target { target, mut inner } = self; inner.insert("target", target)?; Ok(inner) } } impl OptTarget { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut, { let target = inner.remove("target")?; Ok(OptTarget { target, inner }) } fn retracting(self) -> Result where Inner: UnparsedMut, { let OptTarget { target, mut inner } = self; inner.insert("target", target)?; Ok(inner) } } impl Question { /// Create a new Question Activity /// /// ```rust /// use activitystreams::activity::Question; /// /// let activity = Question::new(); /// ``` pub fn new() -> Self { Question { one_of: None, any_of: None, closed: None, inner: Activity::new(), } } /// Deconstruct the Question into its parts /// /// ```rust /// use activitystreams::activity::Question; /// /// let activity = Question::new(); /// /// let (one_of, any_of, activity) = activity.into_parts(); /// ``` pub fn into_parts( self, ) -> ( Option>, Option>, Activity, ) { (self.one_of, self.any_of, self.inner) } fn extending(object: Object) -> Result { let mut inner = Activity::extending(object)?; let one_of = inner.remove("oneOf")?; let any_of = inner.remove("anyOf")?; let closed = inner.remove("closed")?; Ok(Question { one_of, any_of, closed, inner, }) } fn retracting(self) -> Result, serde_json::Error> { let Question { one_of, any_of, closed, mut inner, } = self; inner .insert("oneOf", one_of)? .insert("anyOf", any_of)? .insert("closed", closed)?; inner.retracting() } } impl markers::Base for Activity {} impl markers::Object for Activity {} impl markers::Activity for Activity {} impl markers::Base for ActivityActor where Inner: markers::Base {} impl markers::Object for ActivityActor where Inner: markers::Object {} impl markers::Activity for ActivityActor where Inner: markers::Activity {} impl markers::IntransitiveActivity for ActivityActor where Inner: markers::IntransitiveActivity { } impl markers::Base for ActivityObject where Inner: markers::Base {} impl markers::Object for ActivityObject where Inner: markers::Object {} impl markers::Activity for ActivityObject where Inner: markers::Activity {} impl markers::IntransitiveActivity for ActivityObject where Inner: markers::IntransitiveActivity { } impl markers::Base for Target where Inner: markers::Base {} impl markers::Object for Target where Inner: markers::Object {} impl markers::Activity for Target where Inner: markers::Activity {} impl markers::IntransitiveActivity for Target where Inner: markers::IntransitiveActivity { } impl markers::Base for OptTarget where Inner: markers::Base {} impl markers::Object for OptTarget where Inner: markers::Object {} impl markers::Activity for OptTarget where Inner: markers::Activity {} impl markers::IntransitiveActivity for OptTarget where Inner: markers::IntransitiveActivity { } impl markers::Base for Origin where Inner: markers::Base {} impl markers::Object for Origin where Inner: markers::Object {} impl markers::Activity for Origin where Inner: markers::Activity {} impl markers::IntransitiveActivity for Origin where Inner: markers::IntransitiveActivity { } impl markers::Base for OptOrigin where Inner: markers::Base {} impl markers::Object for OptOrigin where Inner: markers::Object {} impl markers::Activity for OptOrigin where Inner: markers::Activity {} impl markers::IntransitiveActivity for OptOrigin where Inner: markers::IntransitiveActivity { } impl markers::Base for Question {} impl markers::Object for Question {} impl markers::Activity for Question {} impl markers::IntransitiveActivity for Arrive {} impl markers::IntransitiveActivity for Travel {} impl markers::IntransitiveActivity for Question {} impl markers::Activity for ApObject where Inner: markers::Activity {} impl markers::IntransitiveActivity for ApObject where Inner: markers::IntransitiveActivity { } impl Extends for Activity { type Kind = Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Object::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for Activity { type Error = serde_json::Error; fn try_from(object: Object) -> Result { Self::extending(object) } } impl TryFrom> for Object { type Error = serde_json::Error; fn try_from(activity: Activity) -> Result { activity.retracting() } } impl Extends for ActivityActor where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for ActivityActor where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: ActivityActor) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for ActivityObject where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for ActivityObject where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: ActivityObject) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for Origin where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for Origin where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: Origin) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for OptOrigin where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for OptOrigin where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: OptOrigin) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for Target where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for Target where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: Target) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for OptTarget where Inner: Extends + UnparsedMut, { type Kind = Inner::Kind; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Inner::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for OptTarget where Inner: TryFrom, Error = serde_json::Error> + UnparsedMut, { type Error = serde_json::Error; fn try_from(object: Object) -> Result { let inner = Inner::try_from(object)?; Self::extending(inner) } } impl TryFrom> for Object where Object: TryFrom, Inner: UnparsedMut, { type Error = serde_json::Error; fn try_from(activity: OptTarget) -> Result { let inner = activity.retracting()?; TryFrom::try_from(inner) } } impl Extends for Question { type Kind = QuestionType; type Error = serde_json::Error; fn extends(base: Base) -> Result { let inner = Object::extends(base)?; Self::extending(inner) } fn retracts(self) -> Result, Self::Error> { let inner = self.retracting()?; inner.retracts() } } impl TryFrom> for Question { type Error = serde_json::Error; fn try_from(object: Object) -> Result { Self::extending(object) } } impl TryFrom for Object { type Error = serde_json::Error; fn try_from(question: Question) -> Result { question.retracting() } } impl UnparsedMut for Activity { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for ActivityActor where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for ActivityObject where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for Origin where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for OptOrigin where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for Target where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for OptTarget where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl UnparsedMut for Question { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl AsBase for Activity { type Kind = Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for Activity { type Kind = Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for Activity { type Kind = Kind; fn activity_ref(&self) -> &Activity { self } fn activity_mut(&mut self) -> &mut Activity { self } } impl AsBase for ActivityActor where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for ActivityActor where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for ActivityActor where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsActivityActor for ActivityActor where Inner: markers::Activity, { type Inner = Inner; fn activity_actor_ref(&self) -> &ActivityActor { self } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self } } impl AsActivityObject for ActivityActor where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner.activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner.activity_object_mut() } } impl AsTarget for ActivityActor where Inner: AsTarget, { type Inner = Inner::Inner; fn target_ref(&self) -> &Target { self.inner.target_ref() } fn target_mut(&mut self) -> &mut Target { self.inner.target_mut() } } impl AsOptTarget for ActivityActor where Inner: AsOptTarget, { type Inner = Inner::Inner; fn opt_target_ref(&self) -> &OptTarget { self.inner.opt_target_ref() } fn opt_target_mut(&mut self) -> &mut OptTarget { self.inner.opt_target_mut() } } impl AsOrigin for ActivityActor where Inner: AsOrigin, { type Inner = Inner::Inner; fn origin_ref(&self) -> &Origin { self.inner.origin_ref() } fn origin_mut(&mut self) -> &mut Origin { self.inner.origin_mut() } } impl AsOptOrigin for ActivityActor where Inner: AsOptOrigin, { type Inner = Inner::Inner; fn opt_origin_ref(&self) -> &OptOrigin { self.inner.opt_origin_ref() } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self.inner.opt_origin_mut() } } impl AsBase for ActivityObject where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for ActivityObject where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for ActivityObject where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsActivityObject for ActivityObject where Inner: markers::Activity, { type Inner = Inner; fn activity_object_ref(&self) -> &ActivityObject { self } fn activity_object_mut(&mut self) -> &mut ActivityObject { self } } impl AsActivityActor for ActivityObject where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner.activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner.activity_actor_mut() } } impl AsTarget for ActivityObject where Inner: AsTarget, { type Inner = Inner::Inner; fn target_ref(&self) -> &Target { self.inner.target_ref() } fn target_mut(&mut self) -> &mut Target { self.inner.target_mut() } } impl AsOptTarget for ActivityObject where Inner: AsOptTarget, { type Inner = Inner::Inner; fn opt_target_ref(&self) -> &OptTarget { self.inner.opt_target_ref() } fn opt_target_mut(&mut self) -> &mut OptTarget { self.inner.opt_target_mut() } } impl AsOrigin for ActivityObject where Inner: AsOrigin, { type Inner = Inner::Inner; fn origin_ref(&self) -> &Origin { self.inner.origin_ref() } fn origin_mut(&mut self) -> &mut Origin { self.inner.origin_mut() } } impl AsOptOrigin for ActivityObject where Inner: AsOptOrigin, { type Inner = Inner::Inner; fn opt_origin_ref(&self) -> &OptOrigin { self.inner.opt_origin_ref() } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self.inner.opt_origin_mut() } } impl AsBase for Target where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for Target where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for Target where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsActivityObject for Target where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner.activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner.activity_object_mut() } } impl AsActivityActor for Target where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner.activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner.activity_actor_mut() } } impl AsTarget for Target where Inner: markers::Activity, { type Inner = Inner; fn target_ref(&self) -> &Target { self } fn target_mut(&mut self) -> &mut Target { self } } impl AsOrigin for Target where Inner: AsOrigin, { type Inner = Inner::Inner; fn origin_ref(&self) -> &Origin { self.inner.origin_ref() } fn origin_mut(&mut self) -> &mut Origin { self.inner.origin_mut() } } impl AsOptOrigin for Target where Inner: AsOptOrigin, { type Inner = Inner::Inner; fn opt_origin_ref(&self) -> &OptOrigin { self.inner.opt_origin_ref() } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self.inner.opt_origin_mut() } } impl AsBase for OptTarget where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for OptTarget where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for OptTarget where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsActivityObject for OptTarget where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner.activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner.activity_object_mut() } } impl AsActivityActor for OptTarget where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner.activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner.activity_actor_mut() } } impl AsOptTarget for OptTarget where Inner: markers::Activity, { type Inner = Inner; fn opt_target_ref(&self) -> &OptTarget { self } fn opt_target_mut(&mut self) -> &mut OptTarget { self } } impl AsOrigin for OptTarget where Inner: AsOrigin, { type Inner = Inner::Inner; fn origin_ref(&self) -> &Origin { self.inner.origin_ref() } fn origin_mut(&mut self) -> &mut Origin { self.inner.origin_mut() } } impl AsOptOrigin for OptTarget where Inner: AsOptOrigin, { type Inner = Inner::Inner; fn opt_origin_ref(&self) -> &OptOrigin { self.inner.opt_origin_ref() } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self.inner.opt_origin_mut() } } impl AsActivity for Origin where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsBase for Origin where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for Origin where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivityObject for Origin where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner.activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner.activity_object_mut() } } impl AsActivityActor for Origin where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner.activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner.activity_actor_mut() } } impl AsTarget for Origin where Inner: AsTarget, { type Inner = Inner::Inner; fn target_ref(&self) -> &Target { self.inner.target_ref() } fn target_mut(&mut self) -> &mut Target { self.inner.target_mut() } } impl AsOptTarget for Origin where Inner: AsOptTarget, { type Inner = Inner::Inner; fn opt_target_ref(&self) -> &OptTarget { self.inner.opt_target_ref() } fn opt_target_mut(&mut self) -> &mut OptTarget { self.inner.opt_target_mut() } } impl AsOrigin for Origin where Inner: markers::Activity, { type Inner = Inner; fn origin_ref(&self) -> &Origin { self } fn origin_mut(&mut self) -> &mut Origin { self } } impl AsBase for OptOrigin where Inner: AsBase, { type Kind = Inner::Kind; fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for OptOrigin where Inner: AsObject, { type Kind = Inner::Kind; fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsActivity for OptOrigin where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner.activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner.activity_mut() } } impl AsActivityObject for OptOrigin where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner.activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner.activity_object_mut() } } impl AsActivityActor for OptOrigin where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner.activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner.activity_actor_mut() } } impl AsTarget for OptOrigin where Inner: AsTarget, { type Inner = Inner::Inner; fn target_ref(&self) -> &Target { self.inner.target_ref() } fn target_mut(&mut self) -> &mut Target { self.inner.target_mut() } } impl AsOptTarget for OptOrigin where Inner: AsOptTarget, { type Inner = Inner::Inner; fn opt_target_ref(&self) -> &OptTarget { self.inner.opt_target_ref() } fn opt_target_mut(&mut self) -> &mut OptTarget { self.inner.opt_target_mut() } } impl AsOptOrigin for OptOrigin where Inner: markers::Activity, { type Inner = Inner; fn opt_origin_ref(&self) -> &OptOrigin { self } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self } } impl AsActivity for Question { type Kind = QuestionType; fn activity_ref(&self) -> &Activity { &self.inner } fn activity_mut(&mut self) -> &mut Activity { &mut self.inner } } impl AsQuestion for Question { fn question_ref(&self) -> &Question { self } fn question_mut(&mut self) -> &mut Question { self } } impl AsActivity for ApObject where Inner: AsActivity, { type Kind = Inner::Kind; fn activity_ref(&self) -> &Activity { self.inner().activity_ref() } fn activity_mut(&mut self) -> &mut Activity { self.inner_mut().activity_mut() } } impl AsActivityActor for ApObject where Inner: AsActivityActor, { type Inner = Inner::Inner; fn activity_actor_ref(&self) -> &ActivityActor { self.inner().activity_actor_ref() } fn activity_actor_mut(&mut self) -> &mut ActivityActor { self.inner_mut().activity_actor_mut() } } impl AsActivityObject for ApObject where Inner: AsActivityObject, { type Inner = Inner::Inner; fn activity_object_ref(&self) -> &ActivityObject { self.inner().activity_object_ref() } fn activity_object_mut(&mut self) -> &mut ActivityObject { self.inner_mut().activity_object_mut() } } impl AsTarget for ApObject where Inner: AsTarget, { type Inner = Inner::Inner; fn target_ref(&self) -> &Target { self.inner().target_ref() } fn target_mut(&mut self) -> &mut Target { self.inner_mut().target_mut() } } impl AsOrigin for ApObject where Inner: AsOrigin, { type Inner = Inner::Inner; fn origin_ref(&self) -> &Origin { self.inner().origin_ref() } fn origin_mut(&mut self) -> &mut Origin { self.inner_mut().origin_mut() } } impl AsOptTarget for ApObject where Inner: AsOptTarget, { type Inner = Inner::Inner; fn opt_target_ref(&self) -> &OptTarget { self.inner().opt_target_ref() } fn opt_target_mut(&mut self) -> &mut OptTarget { self.inner_mut().opt_target_mut() } } impl AsOptOrigin for ApObject where Inner: AsOptOrigin, { type Inner = Inner::Inner; fn opt_origin_ref(&self) -> &OptOrigin { self.inner().opt_origin_ref() } fn opt_origin_mut(&mut self) -> &mut OptOrigin { self.inner_mut().opt_origin_mut() } } impl AsQuestion for ApObject where Inner: AsQuestion, { fn question_ref(&self) -> &Question { self.inner().question_ref() } fn question_mut(&mut self) -> &mut Question { self.inner_mut().question_mut() } } impl ActivityExt for T where T: AsActivity {} impl AsActivityActorExt for T where T: AsActivityActor {} impl AsActivityObjectExt for T where T: AsActivityObject {} impl AsTargetExt for T where T: AsTarget {} impl AsOriginExt for T where T: AsOrigin {} impl AsOptTargetExt for T where T: AsOptTarget {} impl AsOptOriginExt for T where T: AsOptOrigin {} impl QuestionExt for T where T: AsQuestion {} impl Default for Activity where Kind: Default, { fn default() -> Self { Self::new() } } impl Default for Question { fn default() -> Self { Self::new() } }