From 144d0ad0c28c71ebd33b9669aff13bf615887f1f Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Sun, 28 Nov 2021 14:15:04 -0600 Subject: [PATCH] Implement activitypub traits for borrows & pointers --- apub-core/src/activitystreams.rs | 447 +++++++++++++++++++++++++++++++ 1 file changed, 447 insertions(+) diff --git a/apub-core/src/activitystreams.rs b/apub-core/src/activitystreams.rs index 77426dc..73dbd79 100644 --- a/apub-core/src/activitystreams.rs +++ b/apub-core/src/activitystreams.rs @@ -1,5 +1,7 @@ //! Traits desccribing basic activitystreams types +use std::{rc::Rc, sync::Arc}; + use url::Url; /// A type that represents a Public Key @@ -91,3 +93,448 @@ pub fn delivery_inbox<'a>(actor: &'a impl Actor, obj: &impl DeliverableObject) - actor.inbox() } } + +impl<'a, T> PublicKey for &'a T +where + T: PublicKey, +{ + fn id(&self) -> &Url { + T::id(self) + } + + fn owner(&self) -> &Url { + T::owner(self) + } + + fn public_key_pem(&self) -> &str { + T::public_key_pem(self) + } +} + +impl<'a, T> PublicKey for &'a mut T +where + T: PublicKey, +{ + fn id(&self) -> &Url { + T::id(self) + } + + fn owner(&self) -> &Url { + T::owner(self) + } + + fn public_key_pem(&self) -> &str { + T::public_key_pem(self) + } +} + +impl PublicKey for Box +where + T: PublicKey, +{ + fn id(&self) -> &Url { + T::id(self) + } + + fn owner(&self) -> &Url { + T::owner(self) + } + + fn public_key_pem(&self) -> &str { + T::public_key_pem(self) + } +} + +impl PublicKey for Rc +where + T: PublicKey, +{ + fn id(&self) -> &Url { + T::id(self) + } + + fn owner(&self) -> &Url { + T::owner(self) + } + + fn public_key_pem(&self) -> &str { + T::public_key_pem(self) + } +} + +impl PublicKey for Arc +where + T: PublicKey, +{ + fn id(&self) -> &Url { + T::id(self) + } + + fn owner(&self) -> &Url { + T::owner(self) + } + + fn public_key_pem(&self) -> &str { + T::public_key_pem(self) + } +} + +impl<'a, T> Object for &'a T +where + T: Object, +{ + type Kind = T::Kind; + + fn id(&self) -> &Url { + T::id(self) + } + + fn kind(&self) -> &Self::Kind { + T::kind(self) + } +} + +impl<'a, T> Object for &'a mut T +where + T: Object, +{ + type Kind = T::Kind; + + fn id(&self) -> &Url { + T::id(self) + } + + fn kind(&self) -> &Self::Kind { + T::kind(self) + } +} + +impl Object for Box +where + T: Object, +{ + type Kind = T::Kind; + + fn id(&self) -> &Url { + T::id(self) + } + + fn kind(&self) -> &Self::Kind { + T::kind(self) + } +} + +impl Object for Rc +where + T: Object, +{ + type Kind = T::Kind; + + fn id(&self) -> &Url { + T::id(self) + } + + fn kind(&self) -> &Self::Kind { + T::kind(self) + } +} + +impl Object for Arc +where + T: Object, +{ + type Kind = T::Kind; + + fn id(&self) -> &Url { + T::id(self) + } + + fn kind(&self) -> &Self::Kind { + T::kind(self) + } +} + +impl<'a, T> DeliverableObject for &'a T +where + T: DeliverableObject, +{ + fn to(&self) -> &[Url] { + T::to(self) + } + + fn cc(&self) -> &[Url] { + T::cc(self) + } +} + +impl<'a, T> DeliverableObject for &'a mut T +where + T: DeliverableObject, +{ + fn to(&self) -> &[Url] { + T::to(self) + } + + fn cc(&self) -> &[Url] { + T::cc(self) + } +} + +impl DeliverableObject for Box +where + T: DeliverableObject, +{ + fn to(&self) -> &[Url] { + T::to(self) + } + + fn cc(&self) -> &[Url] { + T::cc(self) + } +} + +impl DeliverableObject for Rc +where + T: DeliverableObject, +{ + fn to(&self) -> &[Url] { + T::to(self) + } + + fn cc(&self) -> &[Url] { + T::cc(self) + } +} + +impl DeliverableObject for Arc +where + T: DeliverableObject, +{ + fn to(&self) -> &[Url] { + T::to(self) + } + + fn cc(&self) -> &[Url] { + T::cc(self) + } +} + +impl<'a, T> Activity for &'a T +where + T: Activity, +{ + fn actor_id(&self) -> &Url { + T::actor_id(self) + } + + fn object_id(&self) -> &Url { + T::object_id(self) + } +} + +impl<'a, T> Activity for &'a mut T +where + T: Activity, +{ + fn actor_id(&self) -> &Url { + T::actor_id(self) + } + + fn object_id(&self) -> &Url { + T::object_id(self) + } +} + +impl Activity for Box +where + T: Activity, +{ + fn actor_id(&self) -> &Url { + T::actor_id(self) + } + + fn object_id(&self) -> &Url { + T::object_id(self) + } +} + +impl Activity for Rc +where + T: Activity, +{ + fn actor_id(&self) -> &Url { + T::actor_id(self) + } + + fn object_id(&self) -> &Url { + T::object_id(self) + } +} + +impl Activity for Arc +where + T: Activity, +{ + fn actor_id(&self) -> &Url { + T::actor_id(self) + } + + fn object_id(&self) -> &Url { + T::object_id(self) + } +} + +impl<'a, T> Actor for &'a T +where + T: Actor, +{ + type PublicKey = T::PublicKey; + + fn inbox(&self) -> &Url { + T::inbox(self) + } + + fn outbox(&self) -> &Url { + T::outbox(self) + } + + fn preferred_username(&self) -> &str { + T::preferred_username(self) + } + + fn public_key(&self) -> &Self::PublicKey { + T::public_key(self) + } + + fn name(&self) -> Option<&str> { + T::name(self) + } + + fn shared_inbox(&self) -> Option<&Url> { + T::shared_inbox(self) + } +} + +impl<'a, T> Actor for &'a mut T +where + T: Actor, +{ + type PublicKey = T::PublicKey; + + fn inbox(&self) -> &Url { + T::inbox(self) + } + + fn outbox(&self) -> &Url { + T::outbox(self) + } + + fn preferred_username(&self) -> &str { + T::preferred_username(self) + } + + fn public_key(&self) -> &Self::PublicKey { + T::public_key(self) + } + + fn name(&self) -> Option<&str> { + T::name(self) + } + + fn shared_inbox(&self) -> Option<&Url> { + T::shared_inbox(self) + } +} + +impl Actor for Box +where + T: Actor, +{ + type PublicKey = T::PublicKey; + + fn inbox(&self) -> &Url { + T::inbox(self) + } + + fn outbox(&self) -> &Url { + T::outbox(self) + } + + fn preferred_username(&self) -> &str { + T::preferred_username(self) + } + + fn public_key(&self) -> &Self::PublicKey { + T::public_key(self) + } + + fn name(&self) -> Option<&str> { + T::name(self) + } + + fn shared_inbox(&self) -> Option<&Url> { + T::shared_inbox(self) + } +} + +impl Actor for Rc +where + T: Actor, +{ + type PublicKey = T::PublicKey; + + fn inbox(&self) -> &Url { + T::inbox(self) + } + + fn outbox(&self) -> &Url { + T::outbox(self) + } + + fn preferred_username(&self) -> &str { + T::preferred_username(self) + } + + fn public_key(&self) -> &Self::PublicKey { + T::public_key(self) + } + + fn name(&self) -> Option<&str> { + T::name(self) + } + + fn shared_inbox(&self) -> Option<&Url> { + T::shared_inbox(self) + } +} + +impl Actor for Arc +where + T: Actor, +{ + type PublicKey = T::PublicKey; + + fn inbox(&self) -> &Url { + T::inbox(self) + } + + fn outbox(&self) -> &Url { + T::outbox(self) + } + + fn preferred_username(&self) -> &str { + T::preferred_username(self) + } + + fn public_key(&self) -> &Self::PublicKey { + T::public_key(self) + } + + fn name(&self) -> Option<&str> { + T::name(self) + } + + fn shared_inbox(&self) -> Option<&Url> { + T::shared_inbox(self) + } +}