use crate::{ base::{AsBase, Base, Extends}, markers, object::{ApObject, AsApObject, AsObject, Object}, primitives::{OneOrMany, XsdAnyUri, XsdString}, unparsed::{Unparsed, UnparsedMut, UnparsedMutExt}, }; use typed_builder::TypedBuilder; pub mod kind { pub use activitystreams::actor::kind::*; } use self::kind::*; pub trait AsApActor: markers::Actor { fn ap_actor_ref(&self) -> &ApActor; fn ap_actor_mut(&mut self) -> &mut ApActor; } pub trait ApActorExt: AsApActor { fn inbox<'a>(&'a self) -> &'a XsdAnyUri where Inner: 'a, { &self.ap_actor_ref().inbox } fn set_inbox(&mut self, inbox: XsdAnyUri) -> &mut Self { self.ap_actor_mut().inbox = inbox; self } fn outbox<'a>(&'a self) -> &'a XsdAnyUri where Inner: 'a, { &self.ap_actor_ref().outbox } fn set_outbox(&mut self, outbox: XsdAnyUri) -> &mut Self { self.ap_actor_mut().outbox = outbox; self } fn following<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().following.as_ref() } 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 followers<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().followers.as_ref() } 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 liked<'a>(&'a self) -> Option<&'a XsdAnyUri> where Inner: 'a, { self.ap_actor_ref().liked.as_ref() } 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_liked(&mut self) -> &mut Self { self.ap_actor_mut().liked = None; self } fn streams<'a>(&'a self) -> Option<&'a OneOrMany> where Inner: 'a, { self.ap_actor_ref().streams.as_ref() } 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 preferred_username<'a>(&'a self) -> Option<&'a XsdString> where Inner: 'a, { self.ap_actor_ref().preferred_username.as_ref() } 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 endpoints<'a>(&'a self) -> Option<&'a Endpoints> where Inner: 'a, { self.ap_actor_ref().endpoints.as_ref() } 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 + markers::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 + markers::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 markers::Actor for Application {} impl markers::Actor for Group {} impl markers::Actor for Organization {} impl markers::Actor for Person {} impl markers::Actor for Service {} impl markers::Base for ApActor where Inner: markers::Base {} impl markers::Object for ApActor where Inner: markers::Object {} impl markers::Actor for ApActor where Inner: markers::Actor {} impl Extends for ApActor where Inner: Extends + UnparsedMut + markers::Actor, Kind: serde::de::DeserializeOwned + serde::ser::Serialize, { 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 UnparsedMut for ApActor where Inner: UnparsedMut, { fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } } impl AsBase for ApActor where Inner: AsBase, { fn base_ref(&self) -> &Base { self.inner.base_ref() } fn base_mut(&mut self) -> &mut Base { self.inner.base_mut() } } impl AsObject for ApActor where Inner: AsObject, { fn object_ref(&self) -> &Object { self.inner.object_ref() } fn object_mut(&mut self) -> &mut Object { self.inner.object_mut() } } impl AsApActor for ApActor where Inner: markers::Actor, { fn ap_actor_ref(&self) -> &ApActor { self } fn ap_actor_mut(&mut self) -> &mut ApActor { self } } impl AsApObject for ApActor where Inner1: AsApObject, { fn ap_object_ref(&self) -> &ApObject { self.inner.ap_object_ref() } fn ap_object_mut(&mut self) -> &mut ApObject { self.inner.ap_object_mut() } } impl ApActorExt for T where T: AsApActor {}