use crate::{ object::{Object, ObjectMut, ObjectRef}, primitives::{OneOrMany, Unparsed, XsdAnyUri, XsdString}, traits::{self, Extends, UnparsedMut, UnparsedMutExt}, }; use typed_builder::TypedBuilder; pub mod kind { pub use activitystreams::actor::kind::*; } use self::kind::*; pub trait ApActorRef: traits::Actor { fn ap_actor_ref(&self) -> &ApActor; } pub trait ApActorMut: traits::Actor { fn ap_actor_mut(&mut self) -> &mut ApActor; } pub trait ApActorRefExt: ApActorRef { fn inbox<'a>(&'a self) -> &'a XsdAnyUri where Inner: 'a, { &self.ap_actor_ref().inbox } fn outbox<'a>(&'a self) -> &'a XsdAnyUri where Inner: 'a, { &self.ap_actor_ref().outbox } fn following<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().following.as_ref() } fn followers<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().followers.as_ref() } fn liked<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().liked.as_ref() } fn streams<'a>(&'a self) -> Option<&'a OneOrMany> where Inner: 'a, { self.ap_actor_ref().streams.as_ref() } fn preferred_username<'a>(&'a self) -> Option<&'a XsdString> where Inner: 'a, { self.ap_actor_ref().preferred_username.as_ref() } fn endpoints<'a>(&'a self) -> Option<&'a Endpoints> where Inner: 'a, { self.ap_actor_ref().endpoints.as_ref() } } pub trait ApActorMutExt: ApActorMut { fn set_inbox(&mut self, inbox: XsdAnyUri) -> &mut Self { self.ap_actor_mut().inbox = inbox; self } fn set_outbox(&mut self, outbox: XsdAnyUri) -> &mut Self { self.ap_actor_mut().outbox = outbox; self } fn set_following(&mut self, following: XsdAnyUri) -> &mut Self { self.ap_actor_mut().following = Some(following); self } fn take_following(&mut self) -> Option { self.ap_actor_mut().following.take() } fn delete_following(&mut self) -> &mut Self { self.ap_actor_mut().following = None; self } fn set_followers(&mut self, followers: XsdAnyUri) -> &mut Self { self.ap_actor_mut().followers = Some(followers); self } fn take_followers(&mut self) -> Option { self.ap_actor_mut().followers.take() } fn delete_followers(&mut self) -> &mut Self { self.ap_actor_mut().followers = None; self } fn set_liked(&mut self, liked: XsdAnyUri) -> &mut Self { self.ap_actor_mut().liked = Some(liked); self } fn take_liked(&mut self) -> Option { self.ap_actor_mut().liked.take() } fn delete_likes(&mut self) -> &mut Self { self.ap_actor_mut().liked = None; self } fn set_streams(&mut self, streams: XsdAnyUri) -> &mut Self { self.ap_actor_mut().streams = Some(streams.into()); self } fn set_many_streams(&mut self, items: I) -> &mut Self where I: IntoIterator, { let v: Vec<_> = items.into_iter().collect(); self.ap_actor_mut().streams = Some(v.into()); self } fn add_stream(&mut self, stream: XsdAnyUri) -> &mut Self { let v = match self.ap_actor_mut().streams.take() { Some(mut v) => { v.add(stream); v } None => vec![stream].into(), }; self.ap_actor_mut().streams = Some(v); self } fn take_streams(&mut self) -> Option> { self.ap_actor_mut().streams.take() } fn delete_streams(&mut self) -> &mut Self { self.ap_actor_mut().streams = None; self } fn set_preferred_username(&mut self, string: XsdString) -> &mut Self { self.ap_actor_mut().preferred_username = Some(string); self } fn take_preferred_username(&mut self) -> Option { self.ap_actor_mut().preferred_username.take() } fn delete_preferred_username(&mut self) -> &mut Self { self.ap_actor_mut().preferred_username = None; self } fn set_endpoints(&mut self, endpoints: Endpoints) -> &mut Self { self.ap_actor_mut().endpoints = Some(endpoints); self } fn take_endpoints(&mut self) -> Option { self.ap_actor_mut().endpoints.take() } fn delete_endpoints(&mut self) -> &mut Self { self.ap_actor_mut().endpoints = None; self } } pub type Application = Object; pub type Group = Object; pub type Organization = Object; pub type Person = Object; pub type Service = Object; #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)] #[serde(rename_all = "camelCase")] #[builder(doc)] pub struct ApActor { pub inbox: XsdAnyUri, pub outbox: XsdAnyUri, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub following: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub followers: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub liked: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option, into))] pub streams: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub preferred_username: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub endpoints: Option, #[serde(flatten)] pub inner: Inner, } #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, TypedBuilder)] #[serde(rename_all = "camelCase")] pub struct Endpoints { #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub proxy_url: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub oauth_authorization_endpoint: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub oauth_token_endpoint: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub provide_client_key: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub sign_client_key: Option, #[serde(skip_serializing_if = "Option::is_none")] #[builder(default, setter(strip_option))] pub shared_inbox: Option, } impl ApActor { fn extending(mut inner: Inner) -> Result where Inner: UnparsedMut + traits::Actor, { let inbox = inner.remove("inbox")?; let outbox = inner.remove("outbox")?; let following = inner.remove("following")?; let followers = inner.remove("followers")?; let liked = inner.remove("liked")?; let streams = inner.remove("streams")?; let preferred_username = inner.remove("preferredUsername")?; let endpoints = inner.remove("endpoints")?; Ok(ApActor { inbox, outbox, following, followers, liked, streams, preferred_username, endpoints, inner, }) } fn retracting(self) -> Result where Inner: UnparsedMut + traits::Actor, { let ApActor { inbox, outbox, following, followers, liked, streams, preferred_username, endpoints, mut inner, } = self; inner .insert("endpoints", endpoints)? .insert("preferredUsername", preferred_username)? .insert("streams", streams)? .insert("liked", liked)? .insert("followers", followers)? .insert("following", following)? .insert("outbox", outbox)? .insert("inbox", inbox)?; Ok(inner) } } impl traits::Actor for Application {} impl traits::Actor for Group {} impl traits::Actor for Organization {} impl traits::Actor for Person {} impl traits::Actor for Service {} impl traits::Base for ApActor where Inner: traits::Base {} impl traits::Object for ApActor where Inner: traits::Object {} impl traits::Actor for ApActor where Inner: traits::Actor {} impl Extends for ApActor where Inner: UnparsedMut + traits::Actor, { type Error = serde_json::Error; fn extends(inner: Inner) -> Result { Self::extending(inner) } fn retracts(self) -> Result { self.retracting() } } impl UnparsedMut for ApActor where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl ObjectRef for ApActor where Inner: ObjectRef, { fn object_ref(&self) -> &Object { self.inner.object_ref() } } impl ObjectMut for ApActor where Inner: ObjectMut, { fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl ApActorRef for ApActor where Inner: traits::Actor, { fn ap_actor_ref(&self) -> &ApActor { self } } impl ApActorMut for ApActor where Inner: traits::Actor, { fn ap_actor_mut(&mut self) -> &mut ApActor { self } } impl ApActorRefExt for T where T: ApActorRef {} impl ApActorMutExt for T where T: ApActorMut {}