mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-22 03:40:59 +00:00
Use associated types for Ap traits
This commit is contained in:
parent
a0fef3abc4
commit
1887e9edfb
7 changed files with 116 additions and 86 deletions
|
@ -53,15 +53,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, ApInner> AsApObject<ApInner> for Ext1<Inner, A>
|
impl<Inner, A> AsApObject for Ext1<Inner, A>
|
||||||
where
|
where
|
||||||
Inner: AsApObject<ApInner>,
|
Inner: AsApObject,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_ref()
|
self.inner.ap_object_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_mut()
|
self.inner.ap_object_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,15 +98,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, ApInner> AsApActor<ApInner> for Ext1<Inner, A>
|
impl<Inner, A> AsApActor for Ext1<Inner, A>
|
||||||
where
|
where
|
||||||
Inner: AsApActor<ApInner>,
|
Inner: AsApActor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_ref()
|
self.inner.ap_actor_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_mut()
|
self.inner.ap_actor_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,15 +53,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, ApInner> AsApObject<ApInner> for Ext2<Inner, A, B>
|
impl<Inner, A, B> AsApObject for Ext2<Inner, A, B>
|
||||||
where
|
where
|
||||||
Inner: AsApObject<ApInner>,
|
Inner: AsApObject,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_ref()
|
self.inner.ap_object_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_mut()
|
self.inner.ap_object_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,15 +98,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, ApInner> AsApActor<ApInner> for Ext2<Inner, A, B>
|
impl<Inner, A, B> AsApActor for Ext2<Inner, A, B>
|
||||||
where
|
where
|
||||||
Inner: AsApActor<ApInner>,
|
Inner: AsApActor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_ref()
|
self.inner.ap_actor_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_mut()
|
self.inner.ap_actor_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,15 +56,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, C, ApInner> AsApObject<ApInner> for Ext3<Inner, A, B, C>
|
impl<Inner, A, B, C> AsApObject for Ext3<Inner, A, B, C>
|
||||||
where
|
where
|
||||||
Inner: AsApObject<ApInner>,
|
Inner: AsApObject,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_ref()
|
self.inner.ap_object_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_mut()
|
self.inner.ap_object_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,15 +101,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, C, ApInner> AsApActor<ApInner> for Ext3<Inner, A, B, C>
|
impl<Inner, A, B, C> AsApActor for Ext3<Inner, A, B, C>
|
||||||
where
|
where
|
||||||
Inner: AsApActor<ApInner>,
|
Inner: AsApActor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_ref()
|
self.inner.ap_actor_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_mut()
|
self.inner.ap_actor_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,15 +59,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, C, D, ApInner> AsApObject<ApInner> for Ext4<Inner, A, B, C, D>
|
impl<Inner, A, B, C, D> AsApObject for Ext4<Inner, A, B, C, D>
|
||||||
where
|
where
|
||||||
Inner: AsApObject<ApInner>,
|
Inner: AsApObject,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_ref()
|
self.inner.ap_object_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_mut()
|
self.inner.ap_object_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,15 +104,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner, A, B, C, D, ApInner> AsApActor<ApInner> for Ext4<Inner, A, B, C, D>
|
impl<Inner, A, B, C, D> AsApActor for Ext4<Inner, A, B, C, D>
|
||||||
where
|
where
|
||||||
Inner: AsApActor<ApInner>,
|
Inner: AsApActor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<ApInner> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_ref()
|
self.inner.ap_actor_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self.inner.ap_actor_mut()
|
self.inner.ap_actor_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
84
src/actor.rs
84
src/actor.rs
|
@ -39,12 +39,14 @@ use self::kind::*;
|
||||||
/// Implementation trait for deriving ActivityPub Actor methods for a type
|
/// Implementation trait for deriving ActivityPub Actor methods for a type
|
||||||
///
|
///
|
||||||
/// Any type implementing AsObject will automatically gain methods provided by ApActorExt
|
/// Any type implementing AsObject will automatically gain methods provided by ApActorExt
|
||||||
pub trait AsApActor<Inner>: markers::Actor {
|
pub trait AsApActor: markers::Actor {
|
||||||
|
type Inner;
|
||||||
|
|
||||||
/// Immutable borrow of `ApActor<Inner>`
|
/// Immutable borrow of `ApActor<Inner>`
|
||||||
fn ap_actor_ref(&self) -> &ApActor<Inner>;
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner>;
|
||||||
|
|
||||||
/// Mutable borrow of `ApActor<Inner>`
|
/// Mutable borrow of `ApActor<Inner>`
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner>;
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper methods for interacting with ActivityPub Actor types
|
/// Helper methods for interacting with ActivityPub Actor types
|
||||||
|
@ -52,7 +54,7 @@ pub trait AsApActor<Inner>: markers::Actor {
|
||||||
/// This trait represents methods valid for any ActivityPub Actor.
|
/// This trait represents methods valid for any ActivityPub Actor.
|
||||||
///
|
///
|
||||||
/// Documentation for the fields related to these methods can be found on the `ApActor` struct
|
/// Documentation for the fields related to these methods can be found on the `ApActor` struct
|
||||||
pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
pub trait ApActorExt: AsApActor {
|
||||||
/// Fetch the inbox for the current actor
|
/// Fetch the inbox for the current actor
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -64,7 +66,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn inbox<'a>(&'a self) -> Result<&'a IriString, CheckError>
|
fn inbox<'a>(&'a self) -> Result<&'a IriString, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
let inbox = self.inbox_unchecked();
|
let inbox = self.inbox_unchecked();
|
||||||
|
@ -82,7 +84,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn inbox_unchecked<'a>(&'a self) -> &'a IriString
|
fn inbox_unchecked<'a>(&'a self) -> &'a IriString
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
&self.ap_actor_ref().inbox
|
&self.ap_actor_ref().inbox
|
||||||
}
|
}
|
||||||
|
@ -98,7 +100,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn inbox_mut<'a>(&'a mut self) -> &'a mut IriString
|
fn inbox_mut<'a>(&'a mut self) -> &'a mut IriString
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
&mut self.ap_actor_mut().inbox
|
&mut self.ap_actor_mut().inbox
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn outbox<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
fn outbox<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
self.outbox_unchecked()
|
self.outbox_unchecked()
|
||||||
|
@ -150,7 +152,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn outbox_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
fn outbox_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().outbox.as_ref()
|
self.ap_actor_ref().outbox.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -168,7 +170,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn outbox_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
fn outbox_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().outbox.as_mut()
|
self.ap_actor_mut().outbox.as_mut()
|
||||||
}
|
}
|
||||||
|
@ -238,7 +240,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn following<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
fn following<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
self.following_unchecked()
|
self.following_unchecked()
|
||||||
|
@ -259,7 +261,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn following_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
fn following_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().following.as_ref()
|
self.ap_actor_ref().following.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -277,7 +279,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn following_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
fn following_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().following.as_mut()
|
self.ap_actor_mut().following.as_mut()
|
||||||
}
|
}
|
||||||
|
@ -347,7 +349,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn followers<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
fn followers<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
self.followers_unchecked()
|
self.followers_unchecked()
|
||||||
|
@ -368,7 +370,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn followers_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
fn followers_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().followers.as_ref()
|
self.ap_actor_ref().followers.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -386,7 +388,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn followers_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
fn followers_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().followers.as_mut()
|
self.ap_actor_mut().followers.as_mut()
|
||||||
}
|
}
|
||||||
|
@ -456,7 +458,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn liked<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
fn liked<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
self.liked_unchecked()
|
self.liked_unchecked()
|
||||||
|
@ -477,7 +479,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn liked_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
fn liked_unchecked<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().liked.as_ref()
|
self.ap_actor_ref().liked.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -495,7 +497,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn liked_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
fn liked_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().liked.as_mut()
|
self.ap_actor_mut().liked.as_mut()
|
||||||
}
|
}
|
||||||
|
@ -565,7 +567,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn streams<'a>(&'a self) -> Result<Option<OneOrMany<&'a IriString>>, CheckError>
|
fn streams<'a>(&'a self) -> Result<Option<OneOrMany<&'a IriString>>, CheckError>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
{
|
{
|
||||||
if let Some(streams) = self.streams_unchecked() {
|
if let Some(streams) = self.streams_unchecked() {
|
||||||
|
@ -592,7 +594,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn streams_unchecked<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
|
fn streams_unchecked<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().streams.as_ref().map(|o| o.as_ref())
|
self.ap_actor_ref().streams.as_ref().map(|o| o.as_ref())
|
||||||
}
|
}
|
||||||
|
@ -613,7 +615,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn streams_mut<'a>(&'a mut self) -> Option<OneOrMany<&'a mut IriString>>
|
fn streams_mut<'a>(&'a mut self) -> Option<OneOrMany<&'a mut IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().streams.as_mut().map(|o| o.as_mut())
|
self.ap_actor_mut().streams.as_mut().map(|o| o.as_mut())
|
||||||
}
|
}
|
||||||
|
@ -734,7 +736,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn preferred_username<'a>(&'a self) -> Option<&'a str>
|
fn preferred_username<'a>(&'a self) -> Option<&'a str>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().preferred_username.as_deref()
|
self.ap_actor_ref().preferred_username.as_deref()
|
||||||
}
|
}
|
||||||
|
@ -813,7 +815,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
fn endpoints<'a>(&'a self) -> Result<Option<Endpoints<&'a IriString>>, CheckError>
|
fn endpoints<'a>(&'a self) -> Result<Option<Endpoints<&'a IriString>>, CheckError>
|
||||||
where
|
where
|
||||||
Self: BaseExt,
|
Self: BaseExt,
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
if let Some(endpoints) = self.endpoints_unchecked() {
|
if let Some(endpoints) = self.endpoints_unchecked() {
|
||||||
let authority_opt = self.id_unchecked().and_then(|id| id.authority_components());
|
let authority_opt = self.id_unchecked().and_then(|id| id.authority_components());
|
||||||
|
@ -868,7 +870,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_unchecked<'a>(&'a self) -> Option<Endpoints<&'a IriString>>
|
fn endpoints_unchecked<'a>(&'a self) -> Option<Endpoints<&'a IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_ref().endpoints.as_ref().map(|e| e.as_ref())
|
self.ap_actor_ref().endpoints.as_ref().map(|e| e.as_ref())
|
||||||
}
|
}
|
||||||
|
@ -889,7 +891,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut IriString>>
|
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_actor_mut().endpoints.as_mut().map(|e| e.as_mut())
|
self.ap_actor_mut().endpoints.as_mut().map(|e| e.as_mut())
|
||||||
}
|
}
|
||||||
|
@ -1473,28 +1475,32 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner> AsApActor<Inner> for ApActor<Inner>
|
impl<Inner> AsApActor for ApActor<Inner>
|
||||||
where
|
where
|
||||||
Inner: markers::Actor,
|
Inner: markers::Actor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<Inner> {
|
type Inner = Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner1, Inner2> AsApObject<Inner2> for ApActor<Inner1>
|
impl<Inner> AsApObject for ApActor<Inner>
|
||||||
where
|
where
|
||||||
Inner1: AsApObject<Inner2>,
|
Inner: AsApObject,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<Inner2> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_ref()
|
self.inner.ap_object_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<Inner2> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self.inner.ap_object_mut()
|
self.inner.ap_object_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1543,17 +1549,19 @@ impl<Kind> AsObject for Actor<Kind> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, Inner> ApActorExt<Inner> for T where T: AsApActor<Inner> {}
|
impl<T> ApActorExt for T where T: AsApActor {}
|
||||||
|
|
||||||
impl<Inner1, Inner2> AsApActor<Inner2> for ApObject<Inner1>
|
impl<Inner> AsApActor for ApObject<Inner>
|
||||||
where
|
where
|
||||||
Inner1: AsApActor<Inner2>,
|
Inner: AsApActor,
|
||||||
{
|
{
|
||||||
fn ap_actor_ref(&self) -> &ApActor<Inner2> {
|
type Inner = Inner::Inner;
|
||||||
|
|
||||||
|
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
self.inner().ap_actor_ref()
|
self.inner().ap_actor_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner2> {
|
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
self.inner_mut().ap_actor_mut()
|
self.inner_mut().ap_actor_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,12 +49,14 @@ pub trait AsObject: markers::Object {
|
||||||
/// Implementation trait for deriving ActivityPub Object methods for a type
|
/// Implementation trait for deriving ActivityPub Object methods for a type
|
||||||
///
|
///
|
||||||
/// Any type implementing AsApObject will automatically gain methods provided by ApObjectExt
|
/// Any type implementing AsApObject will automatically gain methods provided by ApObjectExt
|
||||||
pub trait AsApObject<Inner>: markers::Object {
|
pub trait AsApObject: markers::Object {
|
||||||
|
type Inner;
|
||||||
|
|
||||||
/// Immutable borrow of `ApObject<Inner>`
|
/// Immutable borrow of `ApObject<Inner>`
|
||||||
fn ap_object_ref(&self) -> &ApObject<Inner>;
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner>;
|
||||||
|
|
||||||
/// Mutable borrow of `ApObject<Inner>`
|
/// Mutable borrow of `ApObject<Inner>`
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<Inner>;
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation trait for deriving Place methods for a type
|
/// Implementation trait for deriving Place methods for a type
|
||||||
|
@ -2786,7 +2788,7 @@ pub trait ObjectExt: AsObject {
|
||||||
/// This trait represents methods valid for any ActivityPub Object.
|
/// This trait represents methods valid for any ActivityPub Object.
|
||||||
///
|
///
|
||||||
/// Documentation for the fields related to these methods can be found on the `ApObject` struct
|
/// Documentation for the fields related to these methods can be found on the `ApObject` struct
|
||||||
pub trait ApObjectExt<Inner>: AsApObject<Inner> {
|
pub trait ApObjectExt: AsApObject {
|
||||||
/// Fetch the shares for the current object
|
/// Fetch the shares for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -2801,7 +2803,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn shares<'a>(&'a self) -> Option<&'a IriString>
|
fn shares<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_object_ref().shares.as_ref()
|
self.ap_object_ref().shares.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -2874,7 +2876,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn likes<'a>(&'a self) -> Option<&'a IriString>
|
fn likes<'a>(&'a self) -> Option<&'a IriString>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_object_ref().likes.as_ref()
|
self.ap_object_ref().likes.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -2947,7 +2949,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn source<'a>(&'a self) -> Option<&'a AnyBase>
|
fn source<'a>(&'a self) -> Option<&'a AnyBase>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_object_ref().source.as_ref()
|
self.ap_object_ref().source.as_ref()
|
||||||
}
|
}
|
||||||
|
@ -3023,7 +3025,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
|
||||||
/// ```
|
/// ```
|
||||||
fn upload_media<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
|
fn upload_media<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
|
||||||
where
|
where
|
||||||
Inner: 'a,
|
Self::Inner: 'a,
|
||||||
{
|
{
|
||||||
self.ap_object_ref()
|
self.ap_object_ref()
|
||||||
.upload_media
|
.upload_media
|
||||||
|
@ -5364,7 +5366,7 @@ impl markers::Base for Tombstone {}
|
||||||
impl markers::Object for Tombstone {}
|
impl markers::Object for Tombstone {}
|
||||||
|
|
||||||
impl<T, Kind> ObjectExt for T where T: AsObject<Kind = Kind> {}
|
impl<T, Kind> ObjectExt for T where T: AsObject<Kind = Kind> {}
|
||||||
impl<T, Inner> ApObjectExt<Inner> for T where T: AsApObject<Inner> {}
|
impl<T> ApObjectExt for T where T: AsApObject {}
|
||||||
impl<T> PlaceExt for T where T: AsPlace {}
|
impl<T> PlaceExt for T where T: AsPlace {}
|
||||||
impl<T> ProfileExt for T where T: AsProfile {}
|
impl<T> ProfileExt for T where T: AsProfile {}
|
||||||
impl<T> RelationshipExt for T where T: AsRelationship {}
|
impl<T> RelationshipExt for T where T: AsRelationship {}
|
||||||
|
@ -5424,15 +5426,17 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner> AsApObject<Inner> for ApObject<Inner>
|
impl<Inner> AsApObject for ApObject<Inner>
|
||||||
where
|
where
|
||||||
Inner: markers::Object,
|
Inner: markers::Object,
|
||||||
{
|
{
|
||||||
fn ap_object_ref(&self) -> &ApObject<Inner> {
|
type Inner = Inner;
|
||||||
|
|
||||||
|
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ap_object_mut(&mut self) -> &mut ApObject<Inner> {
|
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,15 +126,17 @@
|
||||||
//! ///
|
//! ///
|
||||||
//! /// This allows us to access methods related to `inbox`, `outbox`, `following`, `followers`,
|
//! /// This allows us to access methods related to `inbox`, `outbox`, `following`, `followers`,
|
||||||
//! /// `liked`, `streams`, `endpoints`, and more directly from the PublicKey struct
|
//! /// `liked`, `streams`, `endpoints`, and more directly from the PublicKey struct
|
||||||
//! impl<Inner1, Inner2> AsApActor<Inner2> for PublicKey<Inner1>
|
//! impl<Inner> AsApActor for PublicKey<Inner>
|
||||||
//! where
|
//! where
|
||||||
//! Inner1: AsApActor<Inner2>,
|
//! Inner: AsApActor,
|
||||||
//! {
|
//! {
|
||||||
//! fn ap_actor_ref(&self) -> &ApActor<Inner2> {
|
//! type Inner = Inner::Inner;
|
||||||
|
//!
|
||||||
|
//! fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
|
||||||
//! self.inner.ap_actor_ref()
|
//! self.inner.ap_actor_ref()
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn ap_actor_mut(&mut self) -> &mut ApActor<Inner2> {
|
//! fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
|
||||||
//! self.inner.ap_actor_mut()
|
//! self.inner.ap_actor_mut()
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
|
|
Loading…
Reference in a new issue