use crate::{ object::Object, primitives::{OneOrMany, Unparsed, XsdAnyUri, XsdString}, traits::{self, Extends, WithUnparsed, WithUnparsedExt}, }; pub mod kind { pub use activitystreams::actor::kind::*; } use self::kind::*; 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)] #[serde(rename_all = "camelCase")] pub struct ApActor { pub inbox: XsdAnyUri, pub outbox: XsdAnyUri, #[serde(skip_serializing_if = "Option::is_none")] pub following: Option, #[serde(skip_serializing_if = "Option::is_none")] pub followers: Option, #[serde(skip_serializing_if = "Option::is_none")] pub liked: Option, #[serde(skip_serializing_if = "Option::is_none")] pub streams: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub preferred_username: Option, #[serde(skip_serializing_if = "Option::is_none")] pub endpoints: Option, #[serde(flatten)] pub inner: Inner, } #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "camelCase")] pub struct Endpoints { #[serde(skip_serializing_if = "Option::is_none")] pub proxy_url: Option, #[serde(skip_serializing_if = "Option::is_none")] pub oauth_authorization_endpoint: Option, #[serde(skip_serializing_if = "Option::is_none")] pub oauth_token_endpoint: Option, #[serde(skip_serializing_if = "Option::is_none")] pub provide_client_key: Option, #[serde(skip_serializing_if = "Option::is_none")] pub sign_client_key: Option, #[serde(skip_serializing_if = "Option::is_none")] pub shared_inbox: Option, } impl ApActor { fn extending(mut inner: Inner) -> Result where Inner: WithUnparsed + 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: WithUnparsed + 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: WithUnparsed + traits::Actor, { type Error = serde_json::Error; fn extends(inner: Inner) -> Result { Self::extending(inner) } fn retracts(self) -> Result { self.retracting() } } impl WithUnparsed for ApActor where Inner: WithUnparsed, { fn unparsed(&self) -> &Unparsed { self.inner.unparsed() } fn unparsed_mut(&mut self) -> &mut Unparsed { self.inner.unparsed_mut() } }