Compare commits

...

11 commits

Author SHA1 Message Date
asonix 2d2756c2bb Bump version 2023-07-06 11:42:38 -05:00
asonix 658f832d08 Clippy nits 2023-07-06 11:41:54 -05:00
asonix b928f8e77f Add catch-all for nonstandard endpoints 2023-07-06 11:38:00 -05:00
asonix 8f9e2a3f3c Add flake 2023-07-06 11:33:40 -05:00
asonix 8bf3f2fc17 Clippy 2022-12-19 16:10:15 -06:00
asonix a65404b4a9 Be more clear about check failures 2022-12-19 13:53:24 -06:00
asonix 7615a8ab5e Bump iri dep 2022-12-06 18:19:25 -06:00
asonix 1887e9edfb Use associated types for Ap traits 2022-12-06 17:47:16 -06:00
asonix a0fef3abc4 Refactor Kind out of trait signatures 2022-12-06 17:36:34 -06:00
asonix 3887886785 angry at clippy for this 2022-11-26 19:20:40 -06:00
defectivealtruist ea334aa9ce Fix swapped lines of documentation 2022-11-26 21:05:15 +11:00
25 changed files with 2753 additions and 2132 deletions

2
.gitignore vendored
View file

@ -2,3 +2,5 @@
**/*.rs.bk
Cargo.lock
/*/target
/.direnv
/.envrc

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams"
description = "A set of core types and traits for activitystreams data"
version = "0.7.0-alpha.20"
version = "0.7.0-alpha.25"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/activitystreams"
@ -16,10 +16,10 @@ edition = "2021"
members = ["activitystreams-ext", "activitystreams-kinds"]
[dependencies]
activitystreams-kinds = { version = "0.2.1", path = "./activitystreams-kinds/", default-features = false, features = [
activitystreams-kinds = { version = "0.3.0", path = "./activitystreams-kinds/", default-features = false, features = [
"iri-string",
] }
iri-string = { version = "0.5.0", features = ["serde", "serde-std", "std"] }
iri-string = { version = "0.7.0", features = ["serde", "std"] }
mime = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-ext"
description = "Extension types for the ActivityStreams crate"
version = "0.1.0-alpha.2"
version = "0.1.0-alpha.3"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
@ -13,7 +13,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
activitystreams = { version = "0.7.0-alpha.3", path = ".." }
activitystreams = { version = "0.7.0-alpha.21", path = ".." }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -1,10 +1,10 @@
use activitystreams::{
actor::{ApActor, Person},
context,
iri_string::types::IriString,
prelude::*,
security,
unparsed::UnparsedMutExt,
url::Url,
};
use activitystreams_ext::{Ext1, UnparsedExtension};
@ -17,8 +17,8 @@ pub struct PublicKey {
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeyInner {
id: Url,
owner: Url,
id: IriString,
owner: IriString,
public_key_pem: String,
}

View file

@ -1,15 +1,15 @@
use crate::Ext1;
use activitystreams::{
activity::{
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
Question, TargetRef,
Activity, ActivityActor, ActivityObject, AsActivity, AsActivityActor, AsActivityObject,
AsOptOrigin, AsOptTarget, AsOrigin, AsQuestion, AsTarget, OptOrigin, OptTarget, Origin,
Question, Target,
},
actor::{ApActor, AsApActor},
base::{AnyBase, AsBase, Base},
base::{AsBase, Base},
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
markers,
object::{ApObject, AsApObject, AsObject, Object},
primitives::OneOrMany,
};
impl<Inner, A> markers::Base for Ext1<Inner, A> where Inner: markers::Base {}
@ -23,167 +23,198 @@ impl<Inner, A> markers::IntransitiveActivity for Ext1<Inner, A> where
{
}
impl<Inner, A, Kind> AsBase<Kind> for Ext1<Inner, A>
impl<Inner, A> AsBase for Ext1<Inner, A>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, A, Kind> AsObject<Kind> for Ext1<Inner, A>
impl<Inner, A> AsObject for Ext1<Inner, A>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
impl<Inner, A, ApInner> AsApObject<ApInner> for Ext1<Inner, A>
impl<Inner, A> AsApObject for Ext1<Inner, A>
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()
}
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self.inner.ap_object_mut()
}
}
impl<Inner, A, Kind> AsCollection<Kind> for Ext1<Inner, A>
impl<Inner, A> AsCollection for Ext1<Inner, A>
where
Inner: AsCollection<Kind>,
Inner: AsCollection,
{
fn collection_ref(&self) -> &Collection<Kind> {
type Kind = Inner::Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self.inner.collection_ref()
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self.inner.collection_mut()
}
}
impl<Inner, A, Kind> AsCollectionPage<Kind> for Ext1<Inner, A>
impl<Inner, A> AsCollectionPage for Ext1<Inner, A>
where
Inner: AsCollectionPage<Kind>,
Inner: AsCollectionPage,
{
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
type Kind = Inner::Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self.inner.collection_page_ref()
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self.inner.collection_page_mut()
}
}
impl<Inner, A, ApInner> AsApActor<ApInner> for Ext1<Inner, A>
impl<Inner, A> AsApActor for Ext1<Inner, A>
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()
}
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
self.inner.ap_actor_mut()
}
}
impl<Inner, A, Kind> AsActivity<Kind> for Ext1<Inner, A>
impl<Inner, A> AsActivity for Ext1<Inner, A>
where
Inner: AsActivity<Kind>,
Inner: AsActivity,
{
fn activity_ref(&self) -> &Activity<Kind> {
type Kind = Inner::Kind;
fn activity_ref(&self) -> &Activity<Self::Kind> {
self.inner.activity_ref()
}
fn activity_mut(&mut self) -> &mut Activity<Kind> {
fn activity_mut(&mut self) -> &mut Activity<Self::Kind> {
self.inner.activity_mut()
}
}
impl<Inner, A> ActorAndObjectRef for Ext1<Inner, A>
impl<Inner, A> AsActivityActor for Ext1<Inner, A>
where
Inner: ActorAndObjectRef,
Inner: AsActivityActor,
{
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.actor_field_ref()
type Inner = Inner::Inner;
fn activity_actor_ref(&self) -> &ActivityActor<Self::Inner> {
self.inner.activity_actor_ref()
}
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.actor_field_mut()
}
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.object_field_ref()
}
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.object_field_mut()
fn activity_actor_mut(&mut self) -> &mut ActivityActor<Self::Inner> {
self.inner.activity_actor_mut()
}
}
impl<Inner, A> TargetRef for Ext1<Inner, A>
impl<Inner, A> AsActivityObject for Ext1<Inner, A>
where
Inner: TargetRef,
Inner: AsActivityObject,
{
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn activity_object_ref(&self) -> &ActivityObject<Self::Inner> {
self.inner.activity_object_ref()
}
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.target_field_mut()
fn activity_object_mut(&mut self) -> &mut ActivityObject<Self::Inner> {
self.inner.activity_object_mut()
}
}
impl<Inner, A> OriginRef for Ext1<Inner, A>
impl<Inner, A> AsTarget for Ext1<Inner, A>
where
Inner: OriginRef,
Inner: AsTarget,
{
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn target_ref(&self) -> &Target<Self::Inner> {
self.inner.target_ref()
}
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.origin_field_mut()
fn target_mut(&mut self) -> &mut Target<Self::Inner> {
self.inner.target_mut()
}
}
impl<Inner, A> OptTargetRef for Ext1<Inner, A>
impl<Inner, A> AsOrigin for Ext1<Inner, A>
where
Inner: OptTargetRef,
Inner: AsOrigin,
{
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn origin_ref(&self) -> &Origin<Self::Inner> {
self.inner.origin_ref()
}
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.target_field_mut()
fn origin_mut(&mut self) -> &mut Origin<Self::Inner> {
self.inner.origin_mut()
}
}
impl<Inner, A> OptOriginRef for Ext1<Inner, A>
impl<Inner, A> AsOptTarget for Ext1<Inner, A>
where
Inner: OptOriginRef,
Inner: AsOptTarget,
{
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn opt_target_ref(&self) -> &OptTarget<Self::Inner> {
self.inner.opt_target_ref()
}
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.origin_field_mut()
fn opt_target_mut(&mut self) -> &mut OptTarget<Self::Inner> {
self.inner.opt_target_mut()
}
}
impl<Inner, A> AsOptOrigin for Ext1<Inner, A>
where
Inner: AsOptOrigin,
{
type Inner = Inner::Inner;
fn opt_origin_ref(&self) -> &OptOrigin<Self::Inner> {
self.inner.opt_origin_ref()
}
fn opt_origin_mut(&mut self) -> &mut OptOrigin<Self::Inner> {
self.inner.opt_origin_mut()
}
}

View file

@ -1,15 +1,15 @@
use crate::Ext2;
use activitystreams::{
activity::{
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
Question, TargetRef,
Activity, ActivityActor, ActivityObject, AsActivity, AsActivityActor, AsActivityObject,
AsOptOrigin, AsOptTarget, AsOrigin, AsQuestion, AsTarget, OptOrigin, OptTarget, Origin,
Question, Target,
},
actor::{ApActor, AsApActor},
base::{AnyBase, AsBase, Base},
base::{AsBase, Base},
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
markers,
object::{ApObject, AsApObject, AsObject, Object},
primitives::OneOrMany,
};
impl<Inner, A, B> markers::Base for Ext2<Inner, A, B> where Inner: markers::Base {}
@ -23,167 +23,198 @@ impl<Inner, A, B> markers::IntransitiveActivity for Ext2<Inner, A, B> where
{
}
impl<Inner, A, B, Kind> AsBase<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B> AsBase for Ext2<Inner, A, B>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, A, B, Kind> AsObject<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B> AsObject for Ext2<Inner, A, B>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
impl<Inner, A, B, ApInner> AsApObject<ApInner> for Ext2<Inner, A, B>
impl<Inner, A, B> AsApObject for Ext2<Inner, A, B>
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()
}
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self.inner.ap_object_mut()
}
}
impl<Inner, A, B, Kind> AsCollection<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B> AsCollection for Ext2<Inner, A, B>
where
Inner: AsCollection<Kind>,
Inner: AsCollection,
{
fn collection_ref(&self) -> &Collection<Kind> {
type Kind = Inner::Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self.inner.collection_ref()
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self.inner.collection_mut()
}
}
impl<Inner, A, B, Kind> AsCollectionPage<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B> AsCollectionPage for Ext2<Inner, A, B>
where
Inner: AsCollectionPage<Kind>,
Inner: AsCollectionPage,
{
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
type Kind = Inner::Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self.inner.collection_page_ref()
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self.inner.collection_page_mut()
}
}
impl<Inner, A, B, ApInner> AsApActor<ApInner> for Ext2<Inner, A, B>
impl<Inner, A, B> AsApActor for Ext2<Inner, A, B>
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()
}
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
self.inner.ap_actor_mut()
}
}
impl<Inner, A, B, Kind> AsActivity<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B> AsActivity for Ext2<Inner, A, B>
where
Inner: AsActivity<Kind>,
Inner: AsActivity,
{
fn activity_ref(&self) -> &Activity<Kind> {
type Kind = Inner::Kind;
fn activity_ref(&self) -> &Activity<Self::Kind> {
self.inner.activity_ref()
}
fn activity_mut(&mut self) -> &mut Activity<Kind> {
fn activity_mut(&mut self) -> &mut Activity<Self::Kind> {
self.inner.activity_mut()
}
}
impl<Inner, A, B> ActorAndObjectRef for Ext2<Inner, A, B>
impl<Inner, A, B> AsActivityActor for Ext2<Inner, A, B>
where
Inner: ActorAndObjectRef,
Inner: AsActivityActor,
{
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.actor_field_ref()
type Inner = Inner::Inner;
fn activity_actor_ref(&self) -> &ActivityActor<Self::Inner> {
self.inner.activity_actor_ref()
}
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.actor_field_mut()
}
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.object_field_ref()
}
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.object_field_mut()
fn activity_actor_mut(&mut self) -> &mut ActivityActor<Self::Inner> {
self.inner.activity_actor_mut()
}
}
impl<Inner, A, B> TargetRef for Ext2<Inner, A, B>
impl<Inner, A, B> AsActivityObject for Ext2<Inner, A, B>
where
Inner: TargetRef,
Inner: AsActivityObject,
{
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn activity_object_ref(&self) -> &ActivityObject<Self::Inner> {
self.inner.activity_object_ref()
}
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.target_field_mut()
fn activity_object_mut(&mut self) -> &mut ActivityObject<Self::Inner> {
self.inner.activity_object_mut()
}
}
impl<Inner, A, B> OriginRef for Ext2<Inner, A, B>
impl<Inner, A, B> AsTarget for Ext2<Inner, A, B>
where
Inner: OriginRef,
Inner: AsTarget,
{
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn target_ref(&self) -> &Target<Self::Inner> {
self.inner.target_ref()
}
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.origin_field_mut()
fn target_mut(&mut self) -> &mut Target<Self::Inner> {
self.inner.target_mut()
}
}
impl<Inner, A, B> OptTargetRef for Ext2<Inner, A, B>
impl<Inner, A, B> AsOrigin for Ext2<Inner, A, B>
where
Inner: OptTargetRef,
Inner: AsOrigin,
{
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn origin_ref(&self) -> &Origin<Self::Inner> {
self.inner.origin_ref()
}
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.target_field_mut()
fn origin_mut(&mut self) -> &mut Origin<Self::Inner> {
self.inner.origin_mut()
}
}
impl<Inner, A, B> OptOriginRef for Ext2<Inner, A, B>
impl<Inner, A, B> AsOptTarget for Ext2<Inner, A, B>
where
Inner: OptOriginRef,
Inner: AsOptTarget,
{
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn opt_target_ref(&self) -> &OptTarget<Self::Inner> {
self.inner.opt_target_ref()
}
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.origin_field_mut()
fn opt_target_mut(&mut self) -> &mut OptTarget<Self::Inner> {
self.inner.opt_target_mut()
}
}
impl<Inner, A, B> AsOptOrigin for Ext2<Inner, A, B>
where
Inner: AsOptOrigin,
{
type Inner = Inner::Inner;
fn opt_origin_ref(&self) -> &OptOrigin<Self::Inner> {
self.inner.opt_origin_ref()
}
fn opt_origin_mut(&mut self) -> &mut OptOrigin<Self::Inner> {
self.inner.opt_origin_mut()
}
}

View file

@ -1,15 +1,15 @@
use crate::Ext3;
use activitystreams::{
activity::{
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
Question, TargetRef,
Activity, ActivityActor, ActivityObject, AsActivity, AsActivityActor, AsActivityObject,
AsOptOrigin, AsOptTarget, AsOrigin, AsQuestion, AsTarget, OptOrigin, OptTarget, Origin,
Question, Target,
},
actor::{ApActor, AsApActor},
base::{AnyBase, AsBase, Base},
base::{AsBase, Base},
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
markers,
object::{ApObject, AsApObject, AsObject, Object},
primitives::OneOrMany,
};
impl<Inner, A, B, C> markers::Base for Ext3<Inner, A, B, C> where Inner: markers::Base {}
@ -26,167 +26,198 @@ impl<Inner, A, B, C> markers::IntransitiveActivity for Ext3<Inner, A, B, C> wher
{
}
impl<Inner, A, B, C, Kind> AsBase<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsBase for Ext3<Inner, A, B, C>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, A, B, C, Kind> AsObject<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsObject for Ext3<Inner, A, B, C>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
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
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()
}
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self.inner.ap_object_mut()
}
}
impl<Inner, A, B, C, Kind> AsCollection<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsCollection for Ext3<Inner, A, B, C>
where
Inner: AsCollection<Kind>,
Inner: AsCollection,
{
fn collection_ref(&self) -> &Collection<Kind> {
type Kind = Inner::Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self.inner.collection_ref()
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self.inner.collection_mut()
}
}
impl<Inner, A, B, C, Kind> AsCollectionPage<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsCollectionPage for Ext3<Inner, A, B, C>
where
Inner: AsCollectionPage<Kind>,
Inner: AsCollectionPage,
{
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
type Kind = Inner::Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self.inner.collection_page_ref()
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self.inner.collection_page_mut()
}
}
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
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()
}
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
self.inner.ap_actor_mut()
}
}
impl<Inner, A, B, C, Kind> AsActivity<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsActivity for Ext3<Inner, A, B, C>
where
Inner: AsActivity<Kind>,
Inner: AsActivity,
{
fn activity_ref(&self) -> &Activity<Kind> {
type Kind = Inner::Kind;
fn activity_ref(&self) -> &Activity<Self::Kind> {
self.inner.activity_ref()
}
fn activity_mut(&mut self) -> &mut Activity<Kind> {
fn activity_mut(&mut self) -> &mut Activity<Self::Kind> {
self.inner.activity_mut()
}
}
impl<Inner, A, B, C> ActorAndObjectRef for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsActivityActor for Ext3<Inner, A, B, C>
where
Inner: ActorAndObjectRef,
Inner: AsActivityActor,
{
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.actor_field_ref()
type Inner = Inner::Inner;
fn activity_actor_ref(&self) -> &ActivityActor<Self::Inner> {
self.inner.activity_actor_ref()
}
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.actor_field_mut()
}
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.object_field_ref()
}
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.object_field_mut()
fn activity_actor_mut(&mut self) -> &mut ActivityActor<Self::Inner> {
self.inner.activity_actor_mut()
}
}
impl<Inner, A, B, C> TargetRef for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsActivityObject for Ext3<Inner, A, B, C>
where
Inner: TargetRef,
Inner: AsActivityObject,
{
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn activity_object_ref(&self) -> &ActivityObject<Self::Inner> {
self.inner.activity_object_ref()
}
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.target_field_mut()
fn activity_object_mut(&mut self) -> &mut ActivityObject<Self::Inner> {
self.inner.activity_object_mut()
}
}
impl<Inner, A, B, C> OriginRef for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsTarget for Ext3<Inner, A, B, C>
where
Inner: OriginRef,
Inner: AsTarget,
{
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn target_ref(&self) -> &Target<Self::Inner> {
self.inner.target_ref()
}
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.origin_field_mut()
fn target_mut(&mut self) -> &mut Target<Self::Inner> {
self.inner.target_mut()
}
}
impl<Inner, A, B, C> OptTargetRef for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsOrigin for Ext3<Inner, A, B, C>
where
Inner: OptTargetRef,
Inner: AsOrigin,
{
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn origin_ref(&self) -> &Origin<Self::Inner> {
self.inner.origin_ref()
}
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.target_field_mut()
fn origin_mut(&mut self) -> &mut Origin<Self::Inner> {
self.inner.origin_mut()
}
}
impl<Inner, A, B, C> OptOriginRef for Ext3<Inner, A, B, C>
impl<Inner, A, B, C> AsOptTarget for Ext3<Inner, A, B, C>
where
Inner: OptOriginRef,
Inner: AsOptTarget,
{
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn opt_target_ref(&self) -> &OptTarget<Self::Inner> {
self.inner.opt_target_ref()
}
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.origin_field_mut()
fn opt_target_mut(&mut self) -> &mut OptTarget<Self::Inner> {
self.inner.opt_target_mut()
}
}
impl<Inner, A, B, C> AsOptOrigin for Ext3<Inner, A, B, C>
where
Inner: AsOptOrigin,
{
type Inner = Inner::Inner;
fn opt_origin_ref(&self) -> &OptOrigin<Self::Inner> {
self.inner.opt_origin_ref()
}
fn opt_origin_mut(&mut self) -> &mut OptOrigin<Self::Inner> {
self.inner.opt_origin_mut()
}
}

View file

@ -1,15 +1,15 @@
use crate::Ext4;
use activitystreams::{
activity::{
Activity, ActorAndObjectRef, AsActivity, AsQuestion, OptOriginRef, OptTargetRef, OriginRef,
Question, TargetRef,
Activity, ActivityActor, ActivityObject, AsActivity, AsActivityActor, AsActivityObject,
AsOptOrigin, AsOptTarget, AsOrigin, AsQuestion, AsTarget, OptOrigin, OptTarget, Origin,
Question, Target,
},
actor::{ApActor, AsApActor},
base::{AnyBase, AsBase, Base},
base::{AsBase, Base},
collection::{AsCollection, AsCollectionPage, Collection, CollectionPage},
markers,
object::{ApObject, AsApObject, AsObject, Object},
primitives::OneOrMany,
};
impl<Inner, A, B, C, D> markers::Base for Ext4<Inner, A, B, C, D> where Inner: markers::Base {}
@ -29,167 +29,198 @@ impl<Inner, A, B, C, D> markers::IntransitiveActivity for Ext4<Inner, A, B, C, D
{
}
impl<Inner, A, B, C, D, Kind> AsBase<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsBase for Ext4<Inner, A, B, C, D>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, A, B, C, D, Kind> AsObject<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsObject for Ext4<Inner, A, B, C, D>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
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
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()
}
fn ap_object_mut(&mut self) -> &mut ApObject<ApInner> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self.inner.ap_object_mut()
}
}
impl<Inner, A, B, C, D, Kind> AsCollection<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsCollection for Ext4<Inner, A, B, C, D>
where
Inner: AsCollection<Kind>,
Inner: AsCollection,
{
fn collection_ref(&self) -> &Collection<Kind> {
type Kind = Inner::Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self.inner.collection_ref()
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self.inner.collection_mut()
}
}
impl<Inner, A, B, C, D, Kind> AsCollectionPage<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsCollectionPage for Ext4<Inner, A, B, C, D>
where
Inner: AsCollectionPage<Kind>,
Inner: AsCollectionPage,
{
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
type Kind = Inner::Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self.inner.collection_page_ref()
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self.inner.collection_page_mut()
}
}
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
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()
}
fn ap_actor_mut(&mut self) -> &mut ApActor<ApInner> {
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
self.inner.ap_actor_mut()
}
}
impl<Inner, A, B, C, D, Kind> AsActivity<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsActivity for Ext4<Inner, A, B, C, D>
where
Inner: AsActivity<Kind>,
Inner: AsActivity,
{
fn activity_ref(&self) -> &Activity<Kind> {
type Kind = Inner::Kind;
fn activity_ref(&self) -> &Activity<Self::Kind> {
self.inner.activity_ref()
}
fn activity_mut(&mut self) -> &mut Activity<Kind> {
fn activity_mut(&mut self) -> &mut Activity<Self::Kind> {
self.inner.activity_mut()
}
}
impl<Inner, A, B, C, D> ActorAndObjectRef for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsActivityActor for Ext4<Inner, A, B, C, D>
where
Inner: ActorAndObjectRef,
Inner: AsActivityActor,
{
fn actor_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.actor_field_ref()
type Inner = Inner::Inner;
fn activity_actor_ref(&self) -> &ActivityActor<Self::Inner> {
self.inner.activity_actor_ref()
}
fn actor_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.actor_field_mut()
}
fn object_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.object_field_ref()
}
fn object_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.object_field_mut()
fn activity_actor_mut(&mut self) -> &mut ActivityActor<Self::Inner> {
self.inner.activity_actor_mut()
}
}
impl<Inner, A, B, C, D> TargetRef for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsActivityObject for Ext4<Inner, A, B, C, D>
where
Inner: TargetRef,
Inner: AsActivityObject,
{
fn target_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn activity_object_ref(&self) -> &ActivityObject<Self::Inner> {
self.inner.activity_object_ref()
}
fn target_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.target_field_mut()
fn activity_object_mut(&mut self) -> &mut ActivityObject<Self::Inner> {
self.inner.activity_object_mut()
}
}
impl<Inner, A, B, C, D> OriginRef for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsTarget for Ext4<Inner, A, B, C, D>
where
Inner: OriginRef,
Inner: AsTarget,
{
fn origin_field_ref(&self) -> &OneOrMany<AnyBase> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn target_ref(&self) -> &Target<Self::Inner> {
self.inner.target_ref()
}
fn origin_field_mut(&mut self) -> &mut OneOrMany<AnyBase> {
self.inner.origin_field_mut()
fn target_mut(&mut self) -> &mut Target<Self::Inner> {
self.inner.target_mut()
}
}
impl<Inner, A, B, C, D> OptTargetRef for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsOrigin for Ext4<Inner, A, B, C, D>
where
Inner: OptTargetRef,
Inner: AsOrigin,
{
fn target_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.target_field_ref()
type Inner = Inner::Inner;
fn origin_ref(&self) -> &Origin<Self::Inner> {
self.inner.origin_ref()
}
fn target_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.target_field_mut()
fn origin_mut(&mut self) -> &mut Origin<Self::Inner> {
self.inner.origin_mut()
}
}
impl<Inner, A, B, C, D> OptOriginRef for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D> AsOptTarget for Ext4<Inner, A, B, C, D>
where
Inner: OptOriginRef,
Inner: AsOptTarget,
{
fn origin_field_ref(&self) -> &Option<OneOrMany<AnyBase>> {
self.inner.origin_field_ref()
type Inner = Inner::Inner;
fn opt_target_ref(&self) -> &OptTarget<Self::Inner> {
self.inner.opt_target_ref()
}
fn origin_field_mut(&mut self) -> &mut Option<OneOrMany<AnyBase>> {
self.inner.origin_field_mut()
fn opt_target_mut(&mut self) -> &mut OptTarget<Self::Inner> {
self.inner.opt_target_mut()
}
}
impl<Inner, A, B, C, D> AsOptOrigin for Ext4<Inner, A, B, C, D>
where
Inner: AsOptOrigin,
{
type Inner = Inner::Inner;
fn opt_origin_ref(&self) -> &OptOrigin<Self::Inner> {
self.inner.opt_origin_ref()
}
fn opt_origin_mut(&mut self) -> &mut OptOrigin<Self::Inner> {
self.inner.opt_origin_mut()
}
}

View file

@ -1,10 +1,10 @@
//! # An extension API for activitystreams
//! _This crate provides Ext1, Ext2, Ext3, and Ext4 for adding extensions to ActivityStreams types_
//!
//! - Find the code on [git.asonix.dog](https://git.asonix.dog/Aardwolf/activitystreams)
//! - Find the code on [git.asonix.dog](https://git.asonix.dog/asonix/activitystreams)
//! - Read the docs on [docs.rs](https://docs.rs/activitystreams-ext)
//! - Join the matrix channel at [#activitypub:asonix.dog](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog&via=matrix.org&via=t2bot.io)
//! - Hit me up on [mastodon](https://asonix.dog/@asonix)
//! - Hit me up on [mastodon](https://masto.asonix.dog/@asonix)
//!
//! ## Usage
//!
@ -23,7 +23,7 @@
//! prelude::*,
//! security,
//! unparsed::UnparsedMutExt,
//! url::Url,
//! iri_string::types::IriString,
//! };
//! use activitystreams_ext::{Ext1, UnparsedExtension};
//!
@ -36,8 +36,8 @@
//! #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
//! #[serde(rename_all = "camelCase")]
//! pub struct PublicKeyInner {
//! id: Url,
//! owner: Url,
//! id: IriString,
//! owner: IriString,
//! public_key_pem: String,
//! }
//!
@ -264,22 +264,24 @@ impl<Inner, A, B, C, D> Ext4<Inner, A, B, C, D> {
}
}
impl<Inner, A, Kind, Error> Extends<Kind> for Ext1<Inner, A>
impl<Inner, A, Error> Extends for Ext1<Inner, A>
where
Inner: Extends<Kind, Error = Error> + UnparsedMut,
Inner: Extends<Error = Error> + UnparsedMut,
A: UnparsedExtension<Inner, Error = Error>,
Error: From<serde_json::Error> + std::error::Error,
{
type Kind = Inner::Kind;
type Error = Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let mut inner = Inner::extends(base)?;
let ext_one = A::try_from_unparsed(&mut inner)?;
Ok(Ext1 { inner, ext_one })
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let Ext1 { mut inner, ext_one } = self;
ext_one.try_into_unparsed(&mut inner)?;
@ -287,16 +289,18 @@ where
}
}
impl<Inner, A, B, Kind, Error> Extends<Kind> for Ext2<Inner, A, B>
impl<Inner, A, B, Error> Extends for Ext2<Inner, A, B>
where
Inner: Extends<Kind, Error = Error> + UnparsedMut,
Inner: Extends<Error = Error> + UnparsedMut,
A: UnparsedExtension<Inner, Error = Error>,
B: UnparsedExtension<Inner, Error = Error>,
Error: From<serde_json::Error> + std::error::Error,
{
type Kind = Inner::Kind;
type Error = Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let mut inner = Inner::extends(base)?;
let ext_one = A::try_from_unparsed(&mut inner)?;
let ext_two = B::try_from_unparsed(&mut inner)?;
@ -308,7 +312,7 @@ where
})
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let Ext2 {
mut inner,
ext_one,
@ -321,17 +325,19 @@ where
}
}
impl<Inner, A, B, C, Kind, Error> Extends<Kind> for Ext3<Inner, A, B, C>
impl<Inner, A, B, C, Error> Extends for Ext3<Inner, A, B, C>
where
Inner: Extends<Kind, Error = Error> + UnparsedMut,
Inner: Extends<Error = Error> + UnparsedMut,
A: UnparsedExtension<Inner, Error = Error>,
B: UnparsedExtension<Inner, Error = Error>,
C: UnparsedExtension<Inner, Error = Error>,
Error: From<serde_json::Error> + std::error::Error,
{
type Kind = Inner::Kind;
type Error = Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let mut inner = Inner::extends(base)?;
let ext_one = A::try_from_unparsed(&mut inner)?;
let ext_two = B::try_from_unparsed(&mut inner)?;
@ -345,7 +351,7 @@ where
})
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let Ext3 {
mut inner,
ext_one,
@ -360,18 +366,20 @@ where
}
}
impl<Inner, A, B, C, D, Kind, Error> Extends<Kind> for Ext4<Inner, A, B, C, D>
impl<Inner, A, B, C, D, Error> Extends for Ext4<Inner, A, B, C, D>
where
Inner: Extends<Kind, Error = Error> + UnparsedMut,
Inner: Extends<Error = Error> + UnparsedMut,
A: UnparsedExtension<Inner, Error = Error>,
B: UnparsedExtension<Inner, Error = Error>,
C: UnparsedExtension<Inner, Error = Error>,
D: UnparsedExtension<Inner, Error = Error>,
Error: From<serde_json::Error> + std::error::Error,
{
type Kind = Inner::Kind;
type Error = Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let mut inner = Inner::extends(base)?;
let ext_one = A::try_from_unparsed(&mut inner)?;
let ext_two = B::try_from_unparsed(&mut inner)?;
@ -387,7 +395,7 @@ where
})
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let Ext4 {
mut inner,
ext_one,

View file

@ -1,7 +1,7 @@
[package]
name = "activitystreams-kinds"
description = "Type-safe activitystreams 'type' values"
version = "0.2.1"
version = "0.3.0"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/activitystreams"
@ -17,7 +17,7 @@ default = ["url"]
[dependencies]
serde = { version = "1", features = ["derive"] }
url = { version = "2", optional = true }
iri-string = { version = "0.5.0", optional = true }
iri-string = { version = "0.7.0", optional = true }
[dev-dependencies]
anyhow = "1"

View file

@ -33,7 +33,7 @@ pub fn handle_activity(activity: AcceptedActivity) -> Result<(), anyhow::Error>
Ok(())
}
static EXAMPLE_JSON: &str = r#"{"actor":"https://asonix.dog/users/asonix","object":"https://asonix.dog/users/asonix/posts/1","type":"Announce"}"#;
static EXAMPLE_JSON: &str = r#"{"id":"https://asonix.dog/activities/1","actor":"https://asonix.dog/users/asonix","object":"https://asonix.dog/users/asonix/posts/1","type":"Announce"}"#;
fn main() -> Result<(), anyhow::Error> {
handle_activity(serde_json::from_str(EXAMPLE_JSON)?)

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1687709756,
"narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1688590700,
"narHash": "sha256-ZF055rIUP89cVwiLpG5xkJzx00gEuuGFF60Bs/LM3wc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f292b4964cb71f9dfbbd30dc9f511d6165cd109b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View file

@ -0,0 +1,25 @@
{
description = "activitystreams";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
packages.default = pkgs.hello;
devShell = with pkgs; mkShell {
nativeBuildInputs = [ cargo cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}

File diff suppressed because it is too large Load diff

View file

@ -21,6 +21,8 @@
//! # Ok(())
//! # }
//! ```
use std::collections::HashMap;
use crate::{
base::{AsBase, Base, Extends},
checked::CheckError,
@ -30,21 +32,34 @@ use crate::{
primitives::OneOrMany,
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
};
use iri_string::types::IriString;
use iri_string::{components::AuthorityComponents, types::IriString};
pub use activitystreams_kinds::actor as kind;
use self::kind::*;
fn check_opt(
iri: &IriString,
authority_components: Option<&AuthorityComponents>,
) -> Result<(), CheckError> {
if iri.authority_components().as_ref() == authority_components {
Ok(())
} else {
Err(CheckError(Some(iri.clone())))
}
}
/// Implementation trait for deriving ActivityPub Actor methods for a type
///
/// 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>`
fn ap_actor_ref(&self) -> &ApActor<Inner>;
fn ap_actor_ref(&self) -> &ApActor<Self::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
@ -52,7 +67,7 @@ pub trait AsApActor<Inner>: markers::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
pub trait ApActorExt<Inner>: AsApActor<Inner> {
pub trait ApActorExt: AsApActor {
/// Fetch the inbox for the current actor
///
/// ```rust
@ -62,10 +77,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// let inbox_ref = person.inbox();
/// ```
fn inbox<'a, Kind>(&'a self) -> Result<&'a IriString, CheckError>
fn inbox<'a>(&'a self) -> Result<&'a IriString, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
let inbox = self.inbox_unchecked();
self.check_authority(inbox)
@ -82,7 +97,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn inbox_unchecked<'a>(&'a self) -> &'a IriString
where
Inner: 'a,
Self::Inner: 'a,
{
&self.ap_actor_ref().inbox
}
@ -98,7 +113,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn inbox_mut<'a>(&'a mut self) -> &'a mut IriString
where
Inner: 'a,
Self::Inner: 'a,
{
&mut self.ap_actor_mut().inbox
}
@ -129,10 +144,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
///
/// let outbox_ref = person.outbox();
/// ```
fn outbox<'a, Kind>(&'a self) -> Result<Option<&'a IriString>, CheckError>
fn outbox<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
self.outbox_unchecked()
.map(|outbox| self.check_authority(outbox))
@ -150,7 +165,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn outbox_unchecked<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().outbox.as_ref()
}
@ -168,7 +183,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn outbox_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_mut().outbox.as_mut()
}
@ -236,10 +251,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", following);
/// }
/// ```
fn following<'a, Kind>(&'a self) -> Result<Option<&'a IriString>, CheckError>
fn following<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
self.following_unchecked()
.map(|following| self.check_authority(following))
@ -259,7 +274,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn following_unchecked<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().following.as_ref()
}
@ -277,7 +292,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn following_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_mut().following.as_mut()
}
@ -345,10 +360,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", followers);
/// }
/// ```
fn followers<'a, Kind>(&'a self) -> Result<Option<&'a IriString>, CheckError>
fn followers<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
self.followers_unchecked()
.map(|followers| self.check_authority(followers))
@ -368,7 +383,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn followers_unchecked<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().followers.as_ref()
}
@ -386,7 +401,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn followers_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_mut().followers.as_mut()
}
@ -454,10 +469,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", liked);
/// }
/// ```
fn liked<'a, Kind>(&'a self) -> Result<Option<&'a IriString>, CheckError>
fn liked<'a>(&'a self) -> Result<Option<&'a IriString>, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
self.liked_unchecked()
.map(|liked| self.check_authority(liked))
@ -477,7 +492,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn liked_unchecked<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().liked.as_ref()
}
@ -495,7 +510,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn liked_mut<'a>(&'a mut self) -> Option<&'a mut IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_mut().liked.as_mut()
}
@ -563,10 +578,10 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", streams);
/// }
/// ```
fn streams<'a, Kind>(&'a self) -> Result<Option<OneOrMany<&'a IriString>>, CheckError>
fn streams<'a>(&'a self) -> Result<Option<OneOrMany<&'a IriString>>, CheckError>
where
Inner: 'a,
Self: BaseExt<Kind>,
Self::Inner: 'a,
Self: BaseExt,
{
if let Some(streams) = self.streams_unchecked() {
for id in &streams {
@ -592,7 +607,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn streams_unchecked<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().streams.as_ref().map(|o| o.as_ref())
}
@ -613,7 +628,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn streams_mut<'a>(&'a mut self) -> Option<OneOrMany<&'a mut IriString>>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_mut().streams.as_mut().map(|o| o.as_mut())
}
@ -734,7 +749,7 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// ```
fn preferred_username<'a>(&'a self) -> Option<&'a str>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_actor_ref().preferred_username.as_deref()
}
@ -810,45 +825,48 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// # Ok(())
/// # }
/// ```
fn endpoints<'a, Kind>(&'a self) -> Result<Option<Endpoints<&'a IriString>>, CheckError>
fn endpoints<'a>(&'a self) -> Result<Option<&'a Endpoints<IriString>>, CheckError>
where
Self: BaseExt<Kind>,
Inner: 'a,
Kind: 'a,
Self: BaseExt,
Self::Inner: 'a,
{
if let Some(endpoints) = self.endpoints_unchecked() {
let authority_opt = self.id_unchecked().and_then(|id| id.authority_components());
let mut any_failed = false;
any_failed |= endpoints
endpoints
.proxy_url
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
any_failed |= endpoints
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.oauth_authorization_endpoint
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
any_failed |= endpoints
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.oauth_token_endpoint
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
any_failed |= endpoints
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.provide_client_key
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
any_failed |= endpoints
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.sign_client_key
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
any_failed |= endpoints
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.shared_inbox
.map(|u| u.authority_components() != authority_opt)
.unwrap_or(false);
if any_failed {
return Err(CheckError);
}
.as_ref()
.map(|i| check_opt(i, authority_opt.as_ref()))
.transpose()?;
endpoints
.nonstandard
.values()
.try_for_each(|v| check_opt(v, authority_opt.as_ref()))?;
return Ok(Some(endpoints));
}
@ -867,11 +885,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", endpoints);
/// }
/// ```
fn endpoints_unchecked<'a>(&'a self) -> Option<Endpoints<&'a IriString>>
fn endpoints_unchecked<'a>(&'a self) -> Option<&'a Endpoints<IriString>>
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()
}
/// Mutably fetch the endpoints for the current actor
@ -888,11 +906,11 @@ pub trait ApActorExt<Inner>: AsApActor<Inner> {
/// println!("{:?}", endpoints);
/// }
/// ```
fn endpoints_mut<'a>(&'a mut self) -> Option<Endpoints<&'a mut IriString>>
fn endpoints_mut<'a>(&'a mut self) -> Option<&'a mut Endpoints<IriString>>
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()
}
/// Set the endpoints for the current actor
@ -1133,6 +1151,14 @@ pub struct Endpoints<T> {
/// - Functional: true
#[serde(skip_serializing_if = "Option::is_none")]
pub shared_inbox: Option<T>,
/// Any nonstandard endpoints present in the endpoints record end up here.
///
/// Software like Pleroma and Akkoma provide additional URLs here and extending Endpoints
/// specifically the way objects are normally extended isn't possible for nested structs like
/// this.
#[serde(flatten)]
pub nonstandard: HashMap<String, T>,
}
/// A simple type to create an Actor out of any Object
@ -1319,47 +1345,6 @@ impl<Inner> ApActor<Inner> {
}
impl<T> Endpoints<T> {
/// Borrow the current Endpoints struct
///
/// ```rust
/// # fn main() -> Result<(), anyhow::Error> {
/// use activitystreams::{actor::Endpoints, iri};
/// use iri_string::types::IriString;
///
/// let uri = iri!("https://example.com");
///
/// let endpoints: Endpoints<IriString> = Endpoints {
/// shared_inbox: Some(uri.clone()),
/// ..Default::default()
/// };
///
/// assert_eq!(endpoints.as_ref().shared_inbox, Some(&uri));
/// # Ok(())
/// # }
/// ```
pub fn as_ref(&self) -> Endpoints<&T> {
Endpoints {
proxy_url: self.proxy_url.as_ref(),
oauth_authorization_endpoint: self.oauth_authorization_endpoint.as_ref(),
oauth_token_endpoint: self.oauth_token_endpoint.as_ref(),
provide_client_key: self.provide_client_key.as_ref(),
sign_client_key: self.sign_client_key.as_ref(),
shared_inbox: self.shared_inbox.as_ref(),
}
}
/// Mutably borrow the endpoints struct
pub fn as_mut(&mut self) -> Endpoints<&mut T> {
Endpoints {
proxy_url: self.proxy_url.as_mut(),
oauth_authorization_endpoint: self.oauth_authorization_endpoint.as_mut(),
oauth_token_endpoint: self.oauth_token_endpoint.as_mut(),
provide_client_key: self.provide_client_key.as_mut(),
sign_client_key: self.sign_client_key.as_mut(),
shared_inbox: self.shared_inbox.as_mut(),
}
}
/// Map the URLs in Endpoints from T to U
///
/// ```rust
@ -1389,6 +1374,11 @@ impl<T> Endpoints<T> {
provide_client_key: self.provide_client_key.map(f),
sign_client_key: self.sign_client_key.map(f),
shared_inbox: self.shared_inbox.map(f),
nonstandard: self
.nonstandard
.into_iter()
.map(|(k, v)| (k, (f)(v)))
.collect(),
}
}
}
@ -1402,6 +1392,7 @@ impl<T> Default for Endpoints<T> {
provide_client_key: None,
sign_client_key: None,
shared_inbox: None,
nonstandard: HashMap::new(),
}
}
}
@ -1416,19 +1407,20 @@ impl<Inner> markers::Actor for ApActor<Inner> where Inner: markers::Actor {}
impl<Inner> markers::Actor for ApObject<Inner> where Inner: markers::Actor {}
impl<Inner, Kind, Error> Extends<Kind> for ApActor<Inner>
impl<Inner, Error> Extends for ApActor<Inner>
where
Inner: Extends<Kind, Error = Error> + UnparsedMut + markers::Actor,
Inner: Extends<Error = Error> + UnparsedMut + markers::Actor,
Error: From<serde_json::Error> + std::error::Error,
{
type Kind = Inner::Kind;
type Error = Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let inner = Inner::extends(base)?;
Ok(Self::extending(inner)?)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let inner = self.retracting()?;
inner.retracts()
}
@ -1443,66 +1435,76 @@ where
}
}
impl<Inner, Kind> AsBase<Kind> for ApActor<Inner>
impl<Inner> AsBase for ApActor<Inner>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, Kind> AsObject<Kind> for ApActor<Inner>
impl<Inner> AsObject for ApActor<Inner>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
impl<Inner> AsApActor<Inner> for ApActor<Inner>
impl<Inner> AsApActor for ApActor<Inner>
where
Inner: markers::Actor,
{
fn ap_actor_ref(&self) -> &ApActor<Inner> {
type Inner = Inner;
fn ap_actor_ref(&self) -> &ApActor<Self::Inner> {
self
}
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner> {
fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
self
}
}
impl<Inner1, Inner2> AsApObject<Inner2> for ApActor<Inner1>
impl<Inner> AsApObject for ApActor<Inner>
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()
}
fn ap_object_mut(&mut self) -> &mut ApObject<Inner2> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self.inner.ap_object_mut()
}
}
impl<Kind> Extends<Kind> for Actor<Kind> {
impl<Kind> Extends for Actor<Kind> {
type Kind = Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
Object::extends(base).map(Actor)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
self.0.retracts()
}
}
@ -1513,37 +1515,43 @@ impl<Kind> UnparsedMut for Actor<Kind> {
}
}
impl<Kind> AsBase<Kind> for Actor<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for Actor<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.0.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.0.base_mut()
}
}
impl<Kind> AsObject<Kind> for Actor<Kind> {
fn object_ref(&self) -> &Object<Kind> {
impl<Kind> AsObject for Actor<Kind> {
type Kind = Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.0.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.0.object_mut()
}
}
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
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()
}
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()
}
}

View file

@ -38,22 +38,24 @@ use mime::Mime;
/// Implements conversion between `Base<Kind>` and other ActivityStreams objects defined in this
/// crate
pub trait Extends<Kind>: Sized {
pub trait Extends: Sized {
type Kind;
/// The erro produced must be a StdError
type Error: std::error::Error;
/// Produce an object from the Base
fn extends(base: Base<Kind>) -> Result<Self, Self::Error>;
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error>;
/// Produce a base from the object
fn retracts(self) -> Result<Base<Kind>, Self::Error>;
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error>;
}
/// A helper function implemented for all Extends types to easily produce an AnyBase from a given
/// object.
///
/// This is important because many APIs in this crate deal with AnyBases.
pub trait ExtendsExt<Kind>: Extends<Kind> {
pub trait ExtendsExt: Extends {
/// Create an AnyBase from the given object
///
/// ```rust
@ -68,7 +70,7 @@ pub trait ExtendsExt<Kind>: Extends<Kind> {
/// ```
fn into_any_base(self) -> Result<AnyBase, Self::Error>
where
Kind: serde::ser::Serialize,
Self::Kind: serde::ser::Serialize,
Self::Error: From<serde_json::Error>,
{
AnyBase::from_extended(self)
@ -91,7 +93,7 @@ pub trait ExtendsExt<Kind>: Extends<Kind> {
/// ```
fn from_any_base(any_base: AnyBase) -> Result<Option<Self>, Self::Error>
where
Kind: serde::de::DeserializeOwned,
Self::Kind: serde::de::DeserializeOwned,
Self::Error: From<serde_json::Error>,
{
if let Some(base) = any_base.take_base() {
@ -108,12 +110,14 @@ pub trait ExtendsExt<Kind>: Extends<Kind> {
/// Implementation trait for deriving Base methods for a type
///
/// Any type implementating AsBase will automatically gain methods provided by BaseExt
pub trait AsBase<Kind>: markers::Base {
pub trait AsBase: markers::Base {
type Kind;
/// Immutable borrow of `Base<Kind>`
fn base_ref(&self) -> &Base<Kind>;
fn base_ref(&self) -> &Base<Self::Kind>;
/// Mutable borrow of Base<Kind>
fn base_mut(&mut self) -> &mut Base<Kind>;
fn base_mut(&mut self) -> &mut Base<Self::Kind>;
}
/// Helper methods for interacting with Base types
@ -122,7 +126,7 @@ pub trait AsBase<Kind>: markers::Base {
/// Link or an Object.
///
/// Documentation for the fields related to these methods can be found on the `Base` struct
pub trait BaseExt<Kind>: AsBase<Kind> {
pub trait BaseExt: AsBase {
/// Fetch the context for the current object
///
/// ```rust
@ -135,7 +139,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn context<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().context.as_ref()
}
@ -259,7 +263,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
let authority = self
.id_unchecked()
.and_then(|id| id.authority_components())
.ok_or(CheckError)?;
.ok_or_else(|| CheckError(Some(iri.as_ref().to_owned())))?;
check(iri, authority.host(), authority.port())
}
@ -277,7 +281,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn id<'a>(&'a self, host: &str, port: Option<&str>) -> Result<Option<&'a IriString>, CheckError>
where
Kind: 'a,
Self::Kind: 'a,
{
self.id_unchecked()
.and_then(|id| {
@ -286,7 +290,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
if authority.host() == host && authority.port() == port {
Some(Ok(id))
} else {
Some(Err(CheckError))
Some(Err(CheckError(Some(id.clone()))))
}
})
.transpose()
@ -306,7 +310,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn id_unchecked<'a>(&'a self) -> Option<&'a IriString>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().id.as_ref()
}
@ -329,7 +333,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
port: Option<&str>,
) -> Result<Option<&'a mut IriString>, CheckError>
where
Kind: 'a,
Self::Kind: 'a,
{
self.id_mut_unchecked()
.and_then(|id| {
@ -338,7 +342,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
if authority.host() == host && authority.port() == port {
Some(Ok(id))
} else {
Some(Err(CheckError))
Some(Err(CheckError(Some(id.clone()))))
}
})
.transpose()
@ -358,7 +362,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn id_mut_unchecked<'a>(&'a mut self) -> Option<&'a mut IriString>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_mut().id.as_mut()
}
@ -445,9 +449,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// println!("{:?}", kind);
/// }
/// ```
fn kind<'a>(&'a self) -> Option<&'a Kind>
fn kind<'a>(&'a self) -> Option<&'a Self::Kind>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().kind.as_ref()
}
@ -470,9 +474,9 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// # Ok(())
/// # }
/// ```
fn is_kind(&self, kind: &Kind) -> bool
fn is_kind(&self, kind: &Self::Kind) -> bool
where
Kind: PartialEq,
Self::Kind: PartialEq,
{
self.kind() == Some(kind)
}
@ -488,7 +492,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
///
/// video.set_kind(VideoType::Video);
/// ```
fn set_kind(&mut self, kind: Kind) -> &mut Self {
fn set_kind(&mut self, kind: Self::Kind) -> &mut Self {
self.base_mut().kind = Some(kind);
self
}
@ -505,7 +509,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// println!("{:?}", kind);
/// }
/// ```
fn take_kind(&mut self) -> Option<Kind> {
fn take_kind(&mut self) -> Option<Self::Kind> {
self.base_mut().kind.take()
}
@ -541,7 +545,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn name<'a>(&'a self) -> Option<OneOrMany<&'a AnyString>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().name.as_ref().map(|o| o.as_ref())
}
@ -662,7 +666,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn media_type<'a>(&'a self) -> Option<&'a Mime>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().media_type.as_ref().map(|m| m.as_ref())
}
@ -737,7 +741,7 @@ pub trait BaseExt<Kind>: AsBase<Kind> {
/// ```
fn preview<'a>(&'a self) -> Option<OneOrMany<&'a AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.base_ref().preview.as_ref().map(|o| o.as_ref())
}
@ -1047,7 +1051,7 @@ impl<Kind> Base<Kind> {
/// ```
pub fn extend<T>(self) -> Result<T, T::Error>
where
T: Extends<Kind>,
T: Extends<Kind = Kind>,
{
T::extends(self)
}
@ -1066,7 +1070,7 @@ impl<Kind> Base<Kind> {
/// ```
pub fn retract<T>(t: T) -> Result<Self, T::Error>
where
T: Extends<Kind>,
T: Extends<Kind = Kind>,
{
t.retracts()
}
@ -1170,7 +1174,7 @@ impl AnyBase {
Ok(base.into())
}
/// Extend this AnyBase into a kind T where T implements Extends<Kind>
/// Extend this AnyBase into a kind T where T implements Extends
///
/// This method returns Ok(None) when the AnyBase does not contain an extensible object, i.e.
/// it's just an IRI
@ -1186,8 +1190,8 @@ impl AnyBase {
/// ```
pub fn extend<T, Kind>(self) -> Result<Option<T>, T::Error>
where
T: ExtendsExt<Kind>,
<T as Extends<Kind>>::Error: From<serde_json::Error>,
T: ExtendsExt<Kind = Kind>,
<T as Extends>::Error: From<serde_json::Error>,
for<'de> Kind: serde::Deserialize<'de>,
{
T::from_any_base(self)
@ -1205,7 +1209,7 @@ impl AnyBase {
/// ```
pub fn from_extended<T, Kind>(extended: T) -> Result<Self, T::Error>
where
T: Extends<Kind>,
T: Extends<Kind = Kind>,
T::Error: From<serde_json::Error>,
Kind: serde::ser::Serialize,
{
@ -1936,35 +1940,38 @@ impl<Kind> UnparsedMut for Base<Kind> {
}
}
impl<Kind> AsBase<Kind> for Base<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for Base<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self
}
}
impl<Kind> Extends<Kind> for Base<Kind> {
impl<Kind> Extends for Base<Kind> {
type Kind = Kind;
type Error = std::convert::Infallible;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
Ok(base)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
Ok(self)
}
}
impl<T, Kind> ExtendsExt<Kind> for T
impl<T> ExtendsExt for T
where
T: Extends<Kind>,
T: Extends,
T::Error: From<serde_json::Error>,
{
}
impl<T, Kind> BaseExt<Kind> for T where T: AsBase<Kind> {}
impl<T> BaseExt for T where T: AsBase {}
impl From<Base<serde_json::Value>> for AnyBase {
fn from(o: Base<serde_json::Value>) -> Self {

View file

@ -1,11 +1,15 @@
use iri_string::types::IriStr;
use iri_string::types::{IriStr, IriString};
#[derive(Clone, Debug)]
pub struct CheckError;
pub struct CheckError(pub(crate) Option<IriString>);
impl std::fmt::Display for CheckError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "IRI failed host and port check")
if let Some(iri) = &self.0 {
write!(f, "IRI failed host and port check: {}", iri)
} else {
write!(f, "IRI missing")
}
}
}
@ -16,10 +20,13 @@ pub(crate) fn check<T: AsRef<IriStr>>(
host: &str,
port: Option<&str>,
) -> Result<T, CheckError> {
let authority = iri.as_ref().authority_components().ok_or(CheckError)?;
let authority = iri
.as_ref()
.authority_components()
.ok_or_else(|| CheckError(Some(iri.as_ref().to_owned())))?;
if authority.host() != host || authority.port() != port {
return Err(CheckError);
return Err(CheckError(Some(iri.as_ref().to_owned())));
}
Ok(iri)

View file

@ -38,17 +38,21 @@ use self::kind::*;
/// Implementation trait for deriving Collection methods for a type
///
/// Any type implementing AsCollection will automatically gain methods provided by CollectionExt
pub trait AsCollection<Kind>: markers::Collection {
fn collection_ref(&self) -> &Collection<Kind>;
fn collection_mut(&mut self) -> &mut Collection<Kind>;
pub trait AsCollection: markers::Collection {
type Kind;
fn collection_ref(&self) -> &Collection<Self::Kind>;
fn collection_mut(&mut self) -> &mut Collection<Self::Kind>;
}
/// Implementation trait for deriving Collection methods for a type
///
/// Any type implementing AsCollectionPage will automatically gain methods provided by CollectionPageExt
pub trait AsCollectionPage<Kind>: markers::CollectionPage {
fn collection_page_ref(&self) -> &CollectionPage<Kind>;
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind>;
pub trait AsCollectionPage: markers::CollectionPage {
type Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind>;
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind>;
}
/// Implementation trait for deriving Collection methods for a type
@ -66,7 +70,7 @@ pub trait AsOrderedCollectionPage: markers::CollectionPage {
///
/// Documentation for the fields related to these methods can be found on the
/// `Collection` struct
pub trait CollectionExt<Kind>: AsCollection<Kind> {
pub trait CollectionExt: AsCollection {
/// Fetch the items for the current activity
///
/// ```rust
@ -80,7 +84,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn items<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().items.as_ref()
}
@ -209,7 +213,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn ordered_items<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().ordered_items.as_ref()
}
@ -338,7 +342,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn total_items<'a>(&'a self) -> Option<u64>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().total_items
}
@ -408,7 +412,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn current<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().current.as_ref()
}
@ -484,7 +488,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn first<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().first.as_ref()
}
@ -560,7 +564,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
/// ```
fn last<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_ref().last.as_ref()
}
@ -629,7 +633,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
///
/// Documentation for the fields related to these methods can be found on the
/// `CollectionPage` struct
pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
pub trait CollectionPageExt: AsCollectionPage {
/// Fetch the part_of field for the current object
///
/// ```rust
@ -644,7 +648,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// ```
fn part_of<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_page_ref().part_of.as_ref()
}
@ -720,7 +724,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// ```
fn next<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_page_ref().next.as_ref()
}
@ -796,7 +800,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
/// ```
fn prev<'a>(&'a self) -> Option<&'a AnyBase>
where
Kind: 'a,
Self::Kind: 'a,
{
self.collection_page_ref().prev.as_ref()
}
@ -1281,15 +1285,17 @@ impl markers::CollectionPage for OrderedCollectionPage {}
impl<Inner> markers::Collection for ApObject<Inner> where Inner: markers::Collection {}
impl<Inner> markers::CollectionPage for ApObject<Inner> where Inner: markers::CollectionPage {}
impl<Kind> Extends<Kind> for Collection<Kind> {
impl<Kind> Extends for Collection<Kind> {
type Kind = Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let inner = Object::extends(base)?;
Self::extending(inner)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let inner = self.retracting()?;
inner.retracts()
}
@ -1311,15 +1317,17 @@ impl<Kind> TryFrom<Object<Kind>> for Collection<Kind> {
}
}
impl<Kind> Extends<Kind> for CollectionPage<Kind> {
impl<Kind> Extends for CollectionPage<Kind> {
type Kind = Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let inner = Object::extends(base)?;
Self::extending(inner)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let inner = self.retracting()?;
inner.retracts()
}
@ -1341,7 +1349,9 @@ impl<Kind> TryFrom<CollectionPage<Kind>> for Object<Kind> {
}
}
impl Extends<OrderedCollectionPageType> for OrderedCollectionPage {
impl Extends for OrderedCollectionPage {
type Kind = OrderedCollectionPageType;
type Error = serde_json::Error;
fn extends(base: Base<OrderedCollectionPageType>) -> Result<Self, Self::Error> {
@ -1389,77 +1399,93 @@ impl UnparsedMut for OrderedCollectionPage {
}
}
impl<Kind> AsBase<Kind> for Collection<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for Collection<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Kind> AsObject<Kind> for Collection<Kind> {
fn object_ref(&self) -> &Object<Kind> {
impl<Kind> AsObject for Collection<Kind> {
type Kind = Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
&self.inner
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
&mut self.inner
}
}
impl<Kind> AsCollection<Kind> for Collection<Kind> {
fn collection_ref(&self) -> &Collection<Kind> {
impl<Kind> AsCollection for Collection<Kind> {
type Kind = Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self
}
}
impl<Kind> AsBase<Kind> for CollectionPage<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for CollectionPage<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Kind> AsObject<Kind> for CollectionPage<Kind> {
fn object_ref(&self) -> &Object<Kind> {
impl<Kind> AsObject for CollectionPage<Kind> {
type Kind = Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
impl<Kind> AsCollection<Kind> for CollectionPage<Kind> {
fn collection_ref(&self) -> &Collection<Kind> {
impl<Kind> AsCollection for CollectionPage<Kind> {
type Kind = Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
&self.inner
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
&mut self.inner
}
}
impl<Kind> AsCollectionPage<Kind> for CollectionPage<Kind> {
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
impl<Kind> AsCollectionPage for CollectionPage<Kind> {
type Kind = Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self
}
}
impl AsBase<OrderedCollectionPageType> for OrderedCollectionPage {
impl AsBase for OrderedCollectionPage {
type Kind = OrderedCollectionPageType;
fn base_ref(&self) -> &Base<OrderedCollectionPageType> {
self.inner.base_ref()
}
@ -1469,7 +1495,9 @@ impl AsBase<OrderedCollectionPageType> for OrderedCollectionPage {
}
}
impl AsObject<OrderedCollectionPageType> for OrderedCollectionPage {
impl AsObject for OrderedCollectionPage {
type Kind = OrderedCollectionPageType;
fn object_ref(&self) -> &Object<OrderedCollectionPageType> {
self.inner.object_ref()
}
@ -1479,7 +1507,9 @@ impl AsObject<OrderedCollectionPageType> for OrderedCollectionPage {
}
}
impl AsCollection<OrderedCollectionPageType> for OrderedCollectionPage {
impl AsCollection for OrderedCollectionPage {
type Kind = OrderedCollectionPageType;
fn collection_ref(&self) -> &Collection<OrderedCollectionPageType> {
self.inner.collection_ref()
}
@ -1489,7 +1519,9 @@ impl AsCollection<OrderedCollectionPageType> for OrderedCollectionPage {
}
}
impl AsCollectionPage<OrderedCollectionPageType> for OrderedCollectionPage {
impl AsCollectionPage for OrderedCollectionPage {
type Kind = OrderedCollectionPageType;
fn collection_page_ref(&self) -> &CollectionPage<OrderedCollectionPageType> {
&self.inner
}
@ -1509,28 +1541,32 @@ impl AsOrderedCollectionPage for OrderedCollectionPage {
}
}
impl<Inner, Kind> AsCollection<Kind> for ApObject<Inner>
impl<Inner> AsCollection for ApObject<Inner>
where
Inner: AsCollection<Kind>,
Inner: AsCollection,
{
fn collection_ref(&self) -> &Collection<Kind> {
type Kind = Inner::Kind;
fn collection_ref(&self) -> &Collection<Self::Kind> {
self.inner().collection_ref()
}
fn collection_mut(&mut self) -> &mut Collection<Kind> {
fn collection_mut(&mut self) -> &mut Collection<Self::Kind> {
self.inner_mut().collection_mut()
}
}
impl<Inner, Kind> AsCollectionPage<Kind> for ApObject<Inner>
impl<Inner> AsCollectionPage for ApObject<Inner>
where
Inner: AsCollectionPage<Kind>,
Inner: AsCollectionPage,
{
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
type Kind = Inner::Kind;
fn collection_page_ref(&self) -> &CollectionPage<Self::Kind> {
self.inner().collection_page_ref()
}
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
fn collection_page_mut(&mut self) -> &mut CollectionPage<Self::Kind> {
self.inner_mut().collection_page_mut()
}
}
@ -1548,8 +1584,8 @@ where
}
}
impl<T, Kind> CollectionExt<Kind> for T where T: AsCollection<Kind> {}
impl<T, Kind> CollectionPageExt<Kind> for T where T: AsCollectionPage<Kind> {}
impl<T> CollectionExt for T where T: AsCollection {}
impl<T> CollectionPageExt for T where T: AsCollectionPage {}
impl<T> OrderedCollectionPageExt for T where T: AsOrderedCollectionPage {}
impl<Kind> Default for Collection<Kind>

View file

@ -1,10 +1,10 @@
//! # ActivityStreams New
//! _A set of Traits and Types that make up the ActivityStreams and ActivityPub specifications_
//!
//! - Find the code on [git.asonix.dog](https://git.asonix.dog/Aardwolf/activitystreams)
//! - Find the code on [git.asonix.dog](https://git.asonix.dog/asonix/activitystreams)
//! - Read the docs on [docs.rs](https://docs.rs/activitystreams)
//! - Join the matrix channel at [#activitypub:asonix.dog](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog&via=matrix.org&via=t2bot.io)
//! - Hit me up on [mastodon](https://asonix.dog/@asonix)
//! - Join the matrix channel at [#activitypub:matrix.asonix.dog](https://matrix.to/#/!fAEcHyTUdAaKCzIKCt:asonix.dog?via=asonix.dog&via=matrix.org&via=t2bot.io)
//! - Hit me up on [mastodon](https://masto.asonix.dog/@asonix)
//!
//! ## Usage
//!
@ -166,9 +166,9 @@
//! ```rust
//! use activitystreams::{base::BaseExt, context, markers::Activity, iri};
//!
//! fn manipulator<T, Kind>(mut activity: T) -> Result<(), anyhow::Error>
//! fn manipulator<T>(mut activity: T) -> Result<(), anyhow::Error>
//! where
//! T: Activity + BaseExt<Kind>,
//! T: Activity + BaseExt,
//! {
//! activity
//! .set_id(iri!("https://example.com"))
@ -375,8 +375,8 @@ pub mod prelude {
pub use crate::{
activity::{
ActivityExt, ActorAndObjectRefExt, OptOriginRefExt, OptTargetRefExt, OriginRefExt,
QuestionExt, TargetRefExt,
ActivityExt, AsActivityActorExt, AsActivityObjectExt, AsOptOriginExt, AsOptTargetExt,
AsOriginExt, AsTargetExt, QuestionExt,
},
actor::ApActorExt,
base::{BaseExt, ExtendsExt},

View file

@ -36,12 +36,13 @@ use self::kind::MentionType;
/// Implementation trait for deriving Link methods for a type
///
/// Any type implementing AsLink will automatically gain methods provided by LinkExt
pub trait AsLink<Kind>: markers::Link {
pub trait AsLink: markers::Link {
type Kind;
/// Immutable borrow of `Link<Kind>`
fn link_ref(&self) -> &Link<Kind>;
fn link_ref(&self) -> &Link<Self::Kind>;
/// Mutable borrow of `Link<Kind>`
fn link_mut(&mut self) -> &mut Link<Kind>;
fn link_mut(&mut self) -> &mut Link<Self::Kind>;
}
/// Helper methods for interacting with Link types
@ -49,7 +50,7 @@ pub trait AsLink<Kind>: markers::Link {
/// This trait represents methods valid for any ActivityStreams Link.
///
/// Documentation for the fields related to these methods can be found on the `Link` struct
pub trait LinkExt<Kind>: AsLink<Kind> {
pub trait LinkExt: AsLink {
/// Fetch the href for the current object
///
/// ```rust
@ -62,7 +63,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn href<'a>(&'a self) -> Option<&'a IriString>
where
Kind: 'a,
Self::Kind: 'a,
{
self.link_ref().href.as_ref()
}
@ -136,7 +137,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn hreflang<'a>(&'a self) -> Option<&'a str>
where
Kind: 'a,
Self::Kind: 'a,
{
self.link_ref().hreflang.as_deref()
}
@ -210,7 +211,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn rel<'a>(&'a self) -> Option<&'a OneOrMany<String>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.link_ref().rel.as_ref()
}
@ -330,7 +331,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn height<'a>(&'a self) -> Option<u64>
where
Kind: 'a,
Self::Kind: 'a,
{
self.link_ref().height
}
@ -403,7 +404,7 @@ pub trait LinkExt<Kind>: AsLink<Kind> {
/// ```
fn width<'a>(&'a self) -> Option<u64>
where
Kind: 'a,
Self::Kind: 'a,
{
self.link_ref().width
}
@ -618,14 +619,16 @@ impl<Kind> Link<Kind> {
impl<Kind> markers::Base for Link<Kind> {}
impl<Kind> markers::Link for Link<Kind> {}
impl<Kind> Extends<Kind> for Link<Kind> {
impl<Kind> Extends for Link<Kind> {
type Kind = Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
Self::extending(base)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
self.retracting()
}
}
@ -658,27 +661,31 @@ impl<Kind> UnparsedMut for Link<Kind> {
}
}
impl<Kind> AsBase<Kind> for Link<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for Link<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
&self.inner
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
&mut self.inner
}
}
impl<Kind> AsLink<Kind> for Link<Kind> {
fn link_ref(&self) -> &Link<Kind> {
impl<Kind> AsLink for Link<Kind> {
type Kind = Kind;
fn link_ref(&self) -> &Link<Self::Kind> {
self
}
fn link_mut(&mut self) -> &mut Link<Kind> {
fn link_mut(&mut self) -> &mut Link<Self::Kind> {
self
}
}
impl<T, Kind> LinkExt<Kind> for T where T: AsLink<Kind> {}
impl<T> LinkExt for T where T: AsLink {}
impl<Kind> Default for Link<Kind>
where

View file

@ -4,9 +4,9 @@
//! use activitystreams::{base::BaseExt, markers::Activity};
//!
//! /// Applies the name "hi" to any given activity
//! fn manipulator<T, Kind>(mut some_type: T) -> T
//! fn manipulator<T>(mut some_type: T) -> T
//! where
//! T: Activity + BaseExt<Kind>,
//! T: Activity + BaseExt,
//! {
//! some_type.set_name("hi");
//!

View file

@ -36,23 +36,27 @@ use self::kind::*;
/// Implementation trait for deriving Object methods for a type
///
/// Any type implementing AsObject will automatically gain methods provided by ObjectExt
pub trait AsObject<Kind>: markers::Object {
pub trait AsObject: markers::Object {
type Kind;
/// Immutable borrow of `Object<Kind>`
fn object_ref(&self) -> &Object<Kind>;
fn object_ref(&self) -> &Object<Self::Kind>;
/// Mutable borrow of `Object<Kind>`
fn object_mut(&mut self) -> &mut Object<Kind>;
fn object_mut(&mut self) -> &mut Object<Self::Kind>;
}
/// Implementation trait for deriving ActivityPub Object methods for a type
///
/// 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>`
fn ap_object_ref(&self) -> &ApObject<Inner>;
fn ap_object_ref(&self) -> &ApObject<Self::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
@ -105,7 +109,7 @@ pub trait AsTombstone: markers::Object {
/// This trait represents methods valid for any ActivityStreams Object.
///
/// Documentation for the fields related to these methods can be found on the `Object` struct
pub trait ObjectExt<Kind>: AsObject<Kind> {
pub trait ObjectExt: AsObject {
/// Fetch the attachment for the current object
///
/// ```rust
@ -120,7 +124,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn attachment<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().attachment.as_ref()
}
@ -256,7 +260,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn attributed_to<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().attributed_to.as_ref()
}
@ -392,7 +396,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn audience<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().audience.as_ref()
}
@ -526,7 +530,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn content<'a>(&'a self) -> Option<OneOrMany<&'a AnyString>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().content.as_ref().map(|o| o.as_ref())
}
@ -647,7 +651,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn summary<'a>(&'a self) -> Option<OneOrMany<&'a AnyString>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().summary.as_ref().map(|o| o.as_ref())
}
@ -768,7 +772,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn url<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().url.as_ref()
}
@ -904,7 +908,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn generator<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().generator.as_ref()
}
@ -1040,7 +1044,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn icon<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().icon.as_ref()
}
@ -1176,7 +1180,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn image<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().image.as_ref()
}
@ -1312,7 +1316,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn location<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().location.as_ref()
}
@ -1448,7 +1452,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn tag<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().tag.as_ref()
}
@ -1584,7 +1588,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn start_time<'a>(&'a self) -> Option<OffsetDateTime>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref()
.start_time
@ -1662,7 +1666,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn end_time<'a>(&'a self) -> Option<OffsetDateTime>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref()
.end_time
@ -1740,7 +1744,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn duration<'a>(&'a self) -> Option<Duration>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref()
.duration
@ -1820,7 +1824,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn published<'a>(&'a self) -> Option<OffsetDateTime>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref()
.published
@ -1898,7 +1902,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn updated<'a>(&'a self) -> Option<OffsetDateTime>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref()
.updated
@ -1976,7 +1980,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn in_reply_to<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().in_reply_to.as_ref()
}
@ -2112,7 +2116,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn replies<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().replies.as_ref()
}
@ -2248,7 +2252,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn to<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().to.as_ref()
}
@ -2384,7 +2388,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn bto<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().bto.as_ref()
}
@ -2520,7 +2524,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn cc<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().cc.as_ref()
}
@ -2656,7 +2660,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// ```
fn bcc<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
where
Kind: 'a,
Self::Kind: 'a,
{
self.object_ref().bcc.as_ref()
}
@ -2784,7 +2788,7 @@ pub trait ObjectExt<Kind>: AsObject<Kind> {
/// This trait represents methods valid for any ActivityPub Object.
///
/// 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
///
/// ```rust
@ -2799,7 +2803,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// ```
fn shares<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_object_ref().shares.as_ref()
}
@ -2872,7 +2876,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// ```
fn likes<'a>(&'a self) -> Option<&'a IriString>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_object_ref().likes.as_ref()
}
@ -2945,7 +2949,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// ```
fn source<'a>(&'a self) -> Option<&'a AnyBase>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_object_ref().source.as_ref()
}
@ -3021,7 +3025,7 @@ pub trait ApObjectExt<Inner>: AsApObject<Inner> {
/// ```
fn upload_media<'a>(&'a self) -> Option<OneOrMany<&'a IriString>>
where
Inner: 'a,
Self::Inner: 'a,
{
self.ap_object_ref()
.upload_media
@ -5131,14 +5135,16 @@ impl Tombstone {
}
}
impl<Kind> Extends<Kind> for Object<Kind> {
impl<Kind> Extends for Object<Kind> {
type Kind = Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
Self::extending(base)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
self.retracting()
}
}
@ -5159,24 +5165,26 @@ impl<Kind> TryFrom<Object<Kind>> for Base<Kind> {
}
}
impl<Inner, Kind> Extends<Kind> for ApObject<Inner>
impl<Inner> Extends for ApObject<Inner>
where
Inner: Extends<Kind, Error = serde_json::Error> + UnparsedMut + markers::Object,
Inner: Extends<Error = serde_json::Error> + UnparsedMut + markers::Object,
{
type Kind = Inner::Kind;
type Error = serde_json::Error;
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
let inner = Inner::extends(base)?;
Self::extending(inner)
}
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
let inner = self.retracting()?;
inner.retracts()
}
}
impl Extends<PlaceType> for Place {
impl Extends for Place {
type Kind = PlaceType;
type Error = serde_json::Error;
fn extends(base: Base<PlaceType>) -> Result<Self, Self::Error> {
@ -5206,7 +5214,8 @@ impl TryFrom<Place> for Object<PlaceType> {
}
}
impl Extends<ProfileType> for Profile {
impl Extends for Profile {
type Kind = ProfileType;
type Error = serde_json::Error;
fn extends(base: Base<ProfileType>) -> Result<Self, Self::Error> {
@ -5236,7 +5245,8 @@ impl TryFrom<Profile> for Object<ProfileType> {
}
}
impl Extends<RelationshipType> for Relationship {
impl Extends for Relationship {
type Kind = RelationshipType;
type Error = serde_json::Error;
fn extends(base: Base<RelationshipType>) -> Result<Self, Self::Error> {
@ -5266,7 +5276,9 @@ impl TryFrom<Relationship> for Object<RelationshipType> {
}
}
impl Extends<TombstoneType> for Tombstone {
impl Extends for Tombstone {
type Kind = TombstoneType;
type Error = serde_json::Error;
fn extends(base: Base<TombstoneType>) -> Result<Self, Self::Error> {
@ -5353,68 +5365,78 @@ impl markers::Object for Relationship {}
impl markers::Base for Tombstone {}
impl markers::Object for Tombstone {}
impl<T, Kind> ObjectExt<Kind> for T where T: AsObject<Kind> {}
impl<T, Inner> ApObjectExt<Inner> for T where T: AsApObject<Inner> {}
impl<T, Kind> ObjectExt for T where T: AsObject<Kind = Kind> {}
impl<T> ApObjectExt for T where T: AsApObject {}
impl<T> PlaceExt for T where T: AsPlace {}
impl<T> ProfileExt for T where T: AsProfile {}
impl<T> RelationshipExt for T where T: AsRelationship {}
impl<T> TombstoneExt for T where T: AsTombstone {}
impl<Kind> AsBase<Kind> for Object<Kind> {
fn base_ref(&self) -> &Base<Kind> {
impl<Kind> AsBase for Object<Kind> {
type Kind = Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
&self.inner
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
&mut self.inner
}
}
impl<Kind> AsObject<Kind> for Object<Kind> {
fn object_ref(&self) -> &Object<Kind> {
impl<Kind> AsObject for Object<Kind> {
type Kind = Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self
}
}
impl<Inner, Kind> AsBase<Kind> for ApObject<Inner>
impl<Inner> AsBase for ApObject<Inner>
where
Inner: AsBase<Kind>,
Inner: AsBase,
{
fn base_ref(&self) -> &Base<Kind> {
type Kind = Inner::Kind;
fn base_ref(&self) -> &Base<Self::Kind> {
self.inner.base_ref()
}
fn base_mut(&mut self) -> &mut Base<Kind> {
fn base_mut(&mut self) -> &mut Base<Self::Kind> {
self.inner.base_mut()
}
}
impl<Inner, Kind> AsObject<Kind> for ApObject<Inner>
impl<Inner> AsObject for ApObject<Inner>
where
Inner: AsObject<Kind>,
Inner: AsObject,
{
fn object_ref(&self) -> &Object<Kind> {
type Kind = Inner::Kind;
fn object_ref(&self) -> &Object<Self::Kind> {
self.inner.object_ref()
}
fn object_mut(&mut self) -> &mut Object<Kind> {
fn object_mut(&mut self) -> &mut Object<Self::Kind> {
self.inner.object_mut()
}
}
impl<Inner> AsApObject<Inner> for ApObject<Inner>
impl<Inner> AsApObject for ApObject<Inner>
where
Inner: markers::Object,
{
fn ap_object_ref(&self) -> &ApObject<Inner> {
type Inner = Inner;
fn ap_object_ref(&self) -> &ApObject<Self::Inner> {
self
}
fn ap_object_mut(&mut self) -> &mut ApObject<Inner> {
fn ap_object_mut(&mut self) -> &mut ApObject<Self::Inner> {
self
}
}
@ -5471,7 +5493,9 @@ where
}
}
impl AsBase<PlaceType> for Place {
impl AsBase for Place {
type Kind = PlaceType;
fn base_ref(&self) -> &Base<PlaceType> {
self.inner.base_ref()
}
@ -5481,7 +5505,9 @@ impl AsBase<PlaceType> for Place {
}
}
impl AsObject<PlaceType> for Place {
impl AsObject for Place {
type Kind = PlaceType;
fn object_ref(&self) -> &Object<PlaceType> {
&self.inner
}
@ -5501,7 +5527,9 @@ impl AsPlace for Place {
}
}
impl AsBase<ProfileType> for Profile {
impl AsBase for Profile {
type Kind = ProfileType;
fn base_ref(&self) -> &Base<ProfileType> {
self.inner.base_ref()
}
@ -5511,7 +5539,9 @@ impl AsBase<ProfileType> for Profile {
}
}
impl AsObject<ProfileType> for Profile {
impl AsObject for Profile {
type Kind = ProfileType;
fn object_ref(&self) -> &Object<ProfileType> {
&self.inner
}
@ -5531,7 +5561,9 @@ impl AsProfile for Profile {
}
}
impl AsBase<RelationshipType> for Relationship {
impl AsBase for Relationship {
type Kind = RelationshipType;
fn base_ref(&self) -> &Base<RelationshipType> {
self.inner.base_ref()
}
@ -5541,7 +5573,9 @@ impl AsBase<RelationshipType> for Relationship {
}
}
impl AsObject<RelationshipType> for Relationship {
impl AsObject for Relationship {
type Kind = RelationshipType;
fn object_ref(&self) -> &Object<RelationshipType> {
&self.inner
}
@ -5561,7 +5595,9 @@ impl AsRelationship for Relationship {
}
}
impl AsBase<TombstoneType> for Tombstone {
impl AsBase for Tombstone {
type Kind = TombstoneType;
fn base_ref(&self) -> &Base<TombstoneType> {
self.inner.base_ref()
}
@ -5571,7 +5607,9 @@ impl AsBase<TombstoneType> for Tombstone {
}
}
impl AsObject<TombstoneType> for Tombstone {
impl AsObject for Tombstone {
type Kind = TombstoneType;
fn object_ref(&self) -> &Object<TombstoneType> {
&self.inner
}

View file

@ -400,13 +400,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
fn count(self) -> usize {
match self.0 {
Either::Left(opt) => {
if opt.is_some() {
1
} else {
0
}
}
Either::Left(opt) => opt.map_or(0, |_| 1),
Either::Right(iter) => iter.count(),
}
}
@ -466,13 +460,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
fn count(self) -> usize {
match self.0 {
Either::Left(opt) => {
if opt.is_some() {
1
} else {
0
}
}
Either::Left(opt) => opt.map_or(0, |_| 1),
Either::Right(iter) => iter.count(),
}
}
@ -532,13 +520,7 @@ impl<T> Iterator for IntoIter<T> {
fn count(self) -> usize {
match self.0 {
Either::Left(opt) => {
if opt.is_some() {
1
} else {
0
}
}
Either::Left(opt) => opt.map_or(0, |_| 1),
Either::Right(iter) => iter.count(),
}
}

View file

@ -222,7 +222,16 @@ impl From<&str> for Unit {
/// A list of units of length that represent valid units for certain ActivityStreams objects
#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
Clone,
Debug,
Default,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
serde::Deserialize,
serde::Serialize,
)]
#[serde(untagged)]
enum Length {
@ -238,6 +247,7 @@ enum Length {
#[serde(rename = "km")]
Kilometers,
#[default]
#[serde(rename = "m")]
Meters,
}
@ -276,12 +286,6 @@ impl Length {
}
}
impl Default for Length {
fn default() -> Self {
Length::Meters
}
}
impl std::str::FromStr for Length {
type Err = LengthError;

View file

@ -46,13 +46,14 @@
//!
//! /// Then, we'll implement Extends so we can produce a PublicKey<Object> from an AnyBase.
//!
//! impl<Inner, Kind> Extends<Kind> for PublicKey<Inner>
//! impl<Inner> Extends for PublicKey<Inner>
//! where
//! Inner: Extends<Kind, Error=serde_json::Error> + UnparsedMut,
//! Inner: Extends<Error=serde_json::Error> + UnparsedMut,
//! {
//! type Kind = Inner::Kind;
//! type Error = serde_json::Error;
//!
//! fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
//! fn extends(base: Base<Self::Kind>) -> Result<Self, Self::Error> {
//! let mut inner = Inner::extends(base)?;
//!
//! Ok(PublicKey {
@ -61,7 +62,7 @@
//! })
//! }
//!
//! fn retracts(self) -> Result<Base<Kind>, Self::Error> {
//! fn retracts(self) -> Result<Base<Self::Kind>, Self::Error> {
//! let PublicKey {
//! public_key,
//! mut inner,
@ -87,15 +88,17 @@
//! ///
//! /// This allows us to access methods related to `context`, `id`, `kind`, `name`,
//! /// `media_type`, and `preview` directly from the PublicKey struct
//! impl<Inner, Kind> AsBase<Kind> for PublicKey<Inner>
//! impl<Inner> AsBase for PublicKey<Inner>
//! where
//! Inner: AsBase<Kind>,
//! Inner: AsBase,
//! {
//! fn base_ref(&self) -> &Base<Kind> {
//! type Kind = Inner::Kind;
//!
//! fn base_ref(&self) -> &Base<Self::Kind> {
//! self.inner.base_ref()
//! }
//!
//! fn base_mut(&mut self) -> &mut Base<Kind> {
//! fn base_mut(&mut self) -> &mut Base<Self::Kind> {
//! self.inner.base_mut()
//! }
//! }
@ -104,15 +107,17 @@
//! ///
//! /// This allows us to access methods related to `url`, `generator`, `start_time`, `duration`,
//! /// and more directly from the PublicKey struct
//! impl<Inner, Kind> AsObject<Kind> for PublicKey<Inner>
//! impl<Inner> AsObject for PublicKey<Inner>
//! where
//! Inner: AsObject<Kind>,
//! Inner: AsObject,
//! {
//! fn object_ref(&self) -> &Object<Kind> {
//! type Kind = Inner::Kind;
//!
//! fn object_ref(&self) -> &Object<Self::Kind> {
//! self.inner.object_ref()
//! }
//!
//! fn object_mut(&mut self) -> &mut Object<Kind> {
//! fn object_mut(&mut self) -> &mut Object<Self::Kind> {
//! self.inner.object_mut()
//! }
//! }
@ -121,15 +126,17 @@
//! ///
//! /// This allows us to access methods related to `inbox`, `outbox`, `following`, `followers`,
//! /// `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
//! 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()
//! }
//!
//! fn ap_actor_mut(&mut self) -> &mut ApActor<Inner2> {
//! fn ap_actor_mut(&mut self) -> &mut ApActor<Self::Inner> {
//! self.inner.ap_actor_mut()
//! }
//! }