The traits! Oh god! The traits
This commit is contained in:
parent
4cb98a6706
commit
d19406f60b
9 changed files with 3581 additions and 303 deletions
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
activitystreams = { version = "0.6.1", default-features = false, features = ["kinds","primitives"] }
|
||||
activitystreams = { version = "0.6.2", default-features = false, features = ["kinds","primitives"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
typed-builder = "0.5.1"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use activitystreams_new::{
|
||||
collection::OrderedCollection,
|
||||
object::{ApObject, Page},
|
||||
prelude::*,
|
||||
traits::Extends,
|
||||
};
|
||||
use anyhow::Error;
|
||||
|
@ -43,11 +44,11 @@ fn main() -> Result<(), Error> {
|
|||
|
||||
let page: ApObject<Page> = serde_json::from_str(page_json)?;
|
||||
println!("{:#?}", page);
|
||||
let mut collection: OrderedCollection = serde_json::from_str(collection_json)?;
|
||||
let mut collection: ApObject<OrderedCollection> = serde_json::from_str(collection_json)?;
|
||||
println!("{:#?}", collection);
|
||||
|
||||
let v: Vec<ApObject<Page>> = collection
|
||||
.items
|
||||
.items()
|
||||
.clone()
|
||||
.many()
|
||||
.into_iter()
|
||||
|
@ -62,7 +63,7 @@ fn main() -> Result<(), Error> {
|
|||
.map(|o| o.retracts().and_then(|o| o.into_generic()))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
collection.items.set_many(v);
|
||||
collection.set_many_items(v);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
1158
src/activity.rs
1158
src/activity.rs
File diff suppressed because it is too large
Load diff
238
src/actor.rs
238
src/actor.rs
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
object::Object,
|
||||
object::{Object, ObjectMut, ObjectRef},
|
||||
primitives::{OneOrMany, Unparsed, XsdAnyUri, XsdString},
|
||||
traits::{self, Extends, WithUnparsed, WithUnparsedExt},
|
||||
traits::{self, Extends, UnparsedMut, UnparsedMutExt},
|
||||
};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
|
@ -11,6 +11,189 @@ pub mod kind {
|
|||
|
||||
use self::kind::*;
|
||||
|
||||
pub trait ApActorRef<Inner>: traits::Actor {
|
||||
fn ap_actor_ref(&self) -> &ApActor<Inner>;
|
||||
}
|
||||
|
||||
pub trait ApActorMut<Inner>: traits::Actor {
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner>;
|
||||
}
|
||||
|
||||
pub trait ApActorRefExt<Inner>: ApActorRef<Inner> {
|
||||
fn inbox<'a>(&'a self) -> &'a XsdAnyUri
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
&self.ap_actor_ref().inbox
|
||||
}
|
||||
|
||||
fn outbox<'a>(&'a self) -> &'a XsdAnyUri
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
&self.ap_actor_ref().outbox
|
||||
}
|
||||
|
||||
fn following<'a>(&'a self) -> Option<&'a XsdAnyUri>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().following.as_ref()
|
||||
}
|
||||
|
||||
fn followers<'a>(&'a self) -> Option<&'a XsdAnyUri>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().followers.as_ref()
|
||||
}
|
||||
|
||||
fn liked<'a>(&'a self) -> Option<&'a XsdAnyUri>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().liked.as_ref()
|
||||
}
|
||||
|
||||
fn streams<'a>(&'a self) -> Option<&'a OneOrMany<XsdAnyUri>>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().streams.as_ref()
|
||||
}
|
||||
|
||||
fn preferred_username<'a>(&'a self) -> Option<&'a XsdString>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().preferred_username.as_ref()
|
||||
}
|
||||
|
||||
fn endpoints<'a>(&'a self) -> Option<&'a Endpoints>
|
||||
where
|
||||
Inner: 'a,
|
||||
{
|
||||
self.ap_actor_ref().endpoints.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ApActorMutExt<Inner>: ApActorMut<Inner> {
|
||||
fn set_inbox(&mut self, inbox: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().inbox = inbox;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_outbox(&mut self, outbox: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().outbox = outbox;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_following(&mut self, following: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().following = Some(following);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_following(&mut self) -> Option<XsdAnyUri> {
|
||||
self.ap_actor_mut().following.take()
|
||||
}
|
||||
|
||||
fn delete_following(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().following = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_followers(&mut self, followers: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().followers = Some(followers);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_followers(&mut self) -> Option<XsdAnyUri> {
|
||||
self.ap_actor_mut().followers.take()
|
||||
}
|
||||
|
||||
fn delete_followers(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().followers = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_liked(&mut self, liked: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().liked = Some(liked);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_liked(&mut self) -> Option<XsdAnyUri> {
|
||||
self.ap_actor_mut().liked.take()
|
||||
}
|
||||
|
||||
fn delete_likes(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().liked = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_streams(&mut self, streams: XsdAnyUri) -> &mut Self {
|
||||
self.ap_actor_mut().streams = Some(streams.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn set_many_streams<I>(&mut self, items: I) -> &mut Self
|
||||
where
|
||||
I: IntoIterator<Item = XsdAnyUri>,
|
||||
{
|
||||
let v: Vec<_> = items.into_iter().collect();
|
||||
self.ap_actor_mut().streams = Some(v.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn add_stream(&mut self, stream: XsdAnyUri) -> &mut Self {
|
||||
let v = match self.ap_actor_mut().streams.take() {
|
||||
Some(mut v) => {
|
||||
v.add(stream);
|
||||
v
|
||||
}
|
||||
None => vec![stream].into(),
|
||||
};
|
||||
self.ap_actor_mut().streams = Some(v);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_streams(&mut self) -> Option<OneOrMany<XsdAnyUri>> {
|
||||
self.ap_actor_mut().streams.take()
|
||||
}
|
||||
|
||||
fn delete_streams(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().streams = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_preferred_username(&mut self, string: XsdString) -> &mut Self {
|
||||
self.ap_actor_mut().preferred_username = Some(string);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_preferred_username(&mut self) -> Option<XsdString> {
|
||||
self.ap_actor_mut().preferred_username.take()
|
||||
}
|
||||
|
||||
fn delete_preferred_username(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().preferred_username = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_endpoints(&mut self, endpoints: Endpoints) -> &mut Self {
|
||||
self.ap_actor_mut().endpoints = Some(endpoints);
|
||||
self
|
||||
}
|
||||
|
||||
fn take_endpoints(&mut self) -> Option<Endpoints> {
|
||||
self.ap_actor_mut().endpoints.take()
|
||||
}
|
||||
|
||||
fn delete_endpoints(&mut self) -> &mut Self {
|
||||
self.ap_actor_mut().endpoints = None;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub type Application = Object<ApplicationType>;
|
||||
pub type Group = Object<GroupType>;
|
||||
pub type Organization = Object<OrganizationType>;
|
||||
|
@ -83,7 +266,7 @@ pub struct Endpoints {
|
|||
impl<Inner> ApActor<Inner> {
|
||||
fn extending(mut inner: Inner) -> Result<Self, serde_json::Error>
|
||||
where
|
||||
Inner: WithUnparsed + traits::Actor,
|
||||
Inner: UnparsedMut + traits::Actor,
|
||||
{
|
||||
let inbox = inner.remove("inbox")?;
|
||||
let outbox = inner.remove("outbox")?;
|
||||
|
@ -109,7 +292,7 @@ impl<Inner> ApActor<Inner> {
|
|||
|
||||
fn retracting(self) -> Result<Inner, serde_json::Error>
|
||||
where
|
||||
Inner: WithUnparsed + traits::Actor,
|
||||
Inner: UnparsedMut + traits::Actor,
|
||||
{
|
||||
let ApActor {
|
||||
inbox,
|
||||
|
@ -149,7 +332,7 @@ impl<Inner> traits::Actor for ApActor<Inner> where Inner: traits::Actor {}
|
|||
|
||||
impl<Inner> Extends<Inner> for ApActor<Inner>
|
||||
where
|
||||
Inner: WithUnparsed + traits::Actor,
|
||||
Inner: UnparsedMut + traits::Actor,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
|
@ -162,15 +345,48 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<Inner> WithUnparsed for ApActor<Inner>
|
||||
impl<Inner> UnparsedMut for ApActor<Inner>
|
||||
where
|
||||
Inner: WithUnparsed,
|
||||
Inner: UnparsedMut,
|
||||
{
|
||||
fn unparsed(&self) -> &Unparsed {
|
||||
self.inner.unparsed()
|
||||
}
|
||||
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||||
self.inner.unparsed_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, Kind> ObjectRef<Kind> for ApActor<Inner>
|
||||
where
|
||||
Inner: ObjectRef<Kind>,
|
||||
{
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
}
|
||||
impl<Inner, Kind> ObjectMut<Kind> for ApActor<Inner>
|
||||
where
|
||||
Inner: ObjectMut<Kind>,
|
||||
{
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner> ApActorRef<Inner> for ApActor<Inner>
|
||||
where
|
||||
Inner: traits::Actor,
|
||||
{
|
||||
fn ap_actor_ref(&self) -> &ApActor<Inner> {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl<Inner> ApActorMut<Inner> for ApActor<Inner>
|
||||
where
|
||||
Inner: traits::Actor,
|
||||
{
|
||||
fn ap_actor_mut(&mut self) -> &mut ApActor<Inner> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Inner> ApActorRefExt<Inner> for T where T: ApActorRef<Inner> {}
|
||||
impl<T, Inner> ApActorMutExt<Inner> for T where T: ApActorMut<Inner> {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
object::{AnyObject, Object},
|
||||
object::{AnyObject, ApObject, Object, ObjectMut, ObjectRef},
|
||||
primitives::{OneOrMany, Unparsed, XsdNonNegativeInteger},
|
||||
traits::{self, Extends, WithUnparsed, WithUnparsedExt},
|
||||
traits::{self, Extends, UnparsedMut, UnparsedMutExt},
|
||||
};
|
||||
use std::convert::TryFrom;
|
||||
use typed_builder::TypedBuilder;
|
||||
|
@ -12,6 +12,264 @@ pub mod kind {
|
|||
|
||||
use self::kind::*;
|
||||
|
||||
pub trait CollectionRef<Kind>: traits::Collection {
|
||||
fn collection_ref(&self) -> &Collection<Kind>;
|
||||
}
|
||||
|
||||
pub trait CollectionMut<Kind>: traits::Collection {
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind>;
|
||||
}
|
||||
|
||||
pub trait CollectionPageRef<Kind>: traits::CollectionPage {
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind>;
|
||||
}
|
||||
|
||||
pub trait CollectionPageMut<Kind>: traits::CollectionPage {
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind>;
|
||||
}
|
||||
|
||||
pub trait OrderedCollectionPageRef: traits::CollectionPage {
|
||||
fn ordered_collection_page_ref(&self) -> &OrderedCollectionPage;
|
||||
}
|
||||
|
||||
pub trait OrderedCollectionPageMut: traits::CollectionPage {
|
||||
fn ordered_collection_page_mut(&mut self) -> &mut OrderedCollectionPage;
|
||||
}
|
||||
|
||||
pub trait CollectionRefExt<Kind>: CollectionRef<Kind> {
|
||||
fn items<'a>(&'a self) -> &'a OneOrMany<AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
&self.collection_ref().items
|
||||
}
|
||||
|
||||
fn total_items<'a>(&'a self) -> Option<&'a XsdNonNegativeInteger>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_ref().total_items.as_ref()
|
||||
}
|
||||
|
||||
fn current<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_ref().current.as_ref()
|
||||
}
|
||||
|
||||
fn first<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_ref().first.as_ref()
|
||||
}
|
||||
|
||||
fn last<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_ref().last.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CollectionMutExt<Kind>: CollectionMut<Kind> {
|
||||
fn set_items<T>(&mut self, item: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_mut().items = item.into().into();
|
||||
self
|
||||
}
|
||||
|
||||
fn set_many_items<I, T>(&mut self, items: I) -> &mut Self
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
let v: Vec<_> = items.into_iter().map(Into::into).collect();
|
||||
self.collection_mut().items = v.into();
|
||||
self
|
||||
}
|
||||
|
||||
fn add_item<T>(&mut self, item: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_mut().items.add(item.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn set_total_items<T>(&mut self, total_items: T) -> &mut Self
|
||||
where
|
||||
T: Into<XsdNonNegativeInteger>,
|
||||
{
|
||||
self.collection_mut().total_items = Some(total_items.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_total_items(&mut self) -> Option<XsdNonNegativeInteger> {
|
||||
self.collection_mut().total_items.take()
|
||||
}
|
||||
|
||||
fn delete_total_items(&mut self) -> &mut Self {
|
||||
self.collection_mut().total_items = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_current<T>(&mut self, current: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_mut().current = Some(current.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_current(&mut self) -> Option<AnyObject> {
|
||||
self.collection_mut().current.take()
|
||||
}
|
||||
|
||||
fn delete_current(&mut self) -> &mut Self {
|
||||
self.collection_mut().current = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_first<T>(&mut self, first: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_mut().first = Some(first.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_first(&mut self) -> Option<AnyObject> {
|
||||
self.collection_mut().first.take()
|
||||
}
|
||||
|
||||
fn delete_first(&mut self) -> &mut Self {
|
||||
self.collection_mut().first = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_last<T>(&mut self, last: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_mut().last = Some(last.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_last(&mut self) -> Option<AnyObject> {
|
||||
self.collection_mut().last.take()
|
||||
}
|
||||
|
||||
fn delete_last(&mut self) -> &mut Self {
|
||||
self.collection_mut().last = None;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CollectionPageRefExt<Kind>: CollectionPageRef<Kind> {
|
||||
fn part_of<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_page_ref().part_of.as_ref()
|
||||
}
|
||||
|
||||
fn next<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_page_ref().next.as_ref()
|
||||
}
|
||||
|
||||
fn prev<'a>(&'a self) -> Option<&'a AnyObject>
|
||||
where
|
||||
Kind: 'a,
|
||||
{
|
||||
self.collection_page_ref().prev.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CollectionPageMutExt<Kind>: CollectionPageMut<Kind> {
|
||||
fn set_part_of<T>(&mut self, part_of: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_page_mut().part_of = Some(part_of.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_part_of(&mut self) -> Option<AnyObject> {
|
||||
self.collection_page_mut().part_of.take()
|
||||
}
|
||||
|
||||
fn delete_part_of(&mut self) -> &mut Self {
|
||||
self.collection_page_mut().part_of = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_next<T>(&mut self, next: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_page_mut().next = Some(next.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_next(&mut self) -> Option<AnyObject> {
|
||||
self.collection_page_mut().next.take()
|
||||
}
|
||||
|
||||
fn delete_next(&mut self) -> &mut Self {
|
||||
self.collection_page_mut().next = None;
|
||||
self
|
||||
}
|
||||
|
||||
fn set_prev<T>(&mut self, prev: T) -> &mut Self
|
||||
where
|
||||
T: Into<AnyObject>,
|
||||
{
|
||||
self.collection_page_mut().prev = Some(prev.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_prev(&mut self) -> Option<AnyObject> {
|
||||
self.collection_page_mut().prev.take()
|
||||
}
|
||||
|
||||
fn delete_prev(&mut self) -> &mut Self {
|
||||
self.collection_page_mut().prev = None;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrderedCollectionPageRefExt: OrderedCollectionPageRef {
|
||||
fn start_index(&self) -> Option<&XsdNonNegativeInteger> {
|
||||
self.ordered_collection_page_ref().start_index.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OrderedCollectionPageMutExt: OrderedCollectionPageMut {
|
||||
fn set_start_index<T>(&mut self, start_index: T) -> &mut Self
|
||||
where
|
||||
T: Into<XsdNonNegativeInteger>,
|
||||
{
|
||||
self.ordered_collection_page_mut().start_index = Some(start_index.into());
|
||||
self
|
||||
}
|
||||
|
||||
fn take_start_index(&mut self) -> Option<XsdNonNegativeInteger> {
|
||||
self.ordered_collection_page_mut().start_index.take()
|
||||
}
|
||||
|
||||
fn delete_start_index(&mut self) -> &mut Self {
|
||||
self.ordered_collection_page_mut().start_index = None;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub type OrderedCollection = Collection<OrderedCollectionType>;
|
||||
pub type UnorderedCollection = Collection<CollectionType>;
|
||||
pub type UnorderedCollectionPage = CollectionPage<CollectionPageType>;
|
||||
|
@ -168,100 +426,72 @@ impl OrderedCollectionPage {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Kind> traits::Base for Collection<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Object for Collection<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Collection for Collection<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Base for Collection<Kind> {}
|
||||
impl<Kind> traits::Object for Collection<Kind> {}
|
||||
impl<Kind> traits::Collection for Collection<Kind> {}
|
||||
|
||||
impl<Kind> traits::Base for CollectionPage<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Object for CollectionPage<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Collection for CollectionPage<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::CollectionPage for CollectionPage<Kind> where Kind: std::fmt::Debug {}
|
||||
impl<Kind> traits::Base for CollectionPage<Kind> {}
|
||||
impl<Kind> traits::Object for CollectionPage<Kind> {}
|
||||
impl<Kind> traits::Collection for CollectionPage<Kind> {}
|
||||
impl<Kind> traits::CollectionPage for CollectionPage<Kind> {}
|
||||
|
||||
impl traits::Base for OrderedCollectionPage {}
|
||||
impl traits::Object for OrderedCollectionPage {}
|
||||
impl traits::Collection for OrderedCollectionPage {}
|
||||
impl traits::CollectionPage for OrderedCollectionPage {}
|
||||
|
||||
impl Extends<Object<CollectionType>> for UnorderedCollection {
|
||||
impl<Kind> Extends<Object<Kind>> for Collection<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(object: Object<CollectionType>) -> Result<Self, Self::Error> {
|
||||
fn extends(object: Object<Kind>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Object<CollectionType>, Self::Error> {
|
||||
fn retracts(self) -> Result<Object<Kind>, Self::Error> {
|
||||
self.retracting()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Object<CollectionType>> for UnorderedCollection {
|
||||
impl<Kind> TryFrom<Collection<Kind>> for Object<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(object: Object<CollectionType>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<UnorderedCollection> for Object<CollectionType> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(collection: UnorderedCollection) -> Result<Self, Self::Error> {
|
||||
fn try_from(collection: Collection<Kind>) -> Result<Self, Self::Error> {
|
||||
collection.retracting()
|
||||
}
|
||||
}
|
||||
|
||||
impl Extends<Object<OrderedCollectionType>> for OrderedCollection {
|
||||
impl<Kind> TryFrom<Object<Kind>> for Collection<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(object: Object<OrderedCollectionType>) -> Result<Self, Self::Error> {
|
||||
fn try_from(object: Object<Kind>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> Extends<Object<Kind>> for CollectionPage<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(object: Object<Kind>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Object<OrderedCollectionType>, Self::Error> {
|
||||
fn retracts(self) -> Result<Object<Kind>, Self::Error> {
|
||||
self.retracting()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Object<OrderedCollectionType>> for OrderedCollection {
|
||||
impl<Kind> TryFrom<Object<Kind>> for CollectionPage<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(object: Object<OrderedCollectionType>) -> Result<Self, Self::Error> {
|
||||
fn try_from(object: Object<Kind>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<OrderedCollection> for Object<OrderedCollectionType> {
|
||||
impl<Kind> TryFrom<CollectionPage<Kind>> for Object<Kind> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(collection: OrderedCollection) -> Result<Self, Self::Error> {
|
||||
collection.retracting()
|
||||
}
|
||||
}
|
||||
|
||||
impl Extends<Object<CollectionPageType>> for UnorderedCollectionPage {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn extends(object: Object<CollectionPageType>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
|
||||
fn retracts(self) -> Result<Object<CollectionPageType>, Self::Error> {
|
||||
self.retracting()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Object<CollectionPageType>> for UnorderedCollectionPage {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(object: Object<CollectionPageType>) -> Result<Self, Self::Error> {
|
||||
Self::extending(object)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<UnorderedCollectionPage> for Object<CollectionPageType> {
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from(collection_page: UnorderedCollectionPage) -> Result<Self, Self::Error> {
|
||||
fn try_from(collection_page: CollectionPage<Kind>) -> Result<Self, Self::Error> {
|
||||
collection_page.retracting()
|
||||
}
|
||||
}
|
||||
|
@ -294,32 +524,171 @@ impl TryFrom<OrderedCollectionPage> for Object<OrderedCollectionPageType> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Kind> WithUnparsed for Collection<Kind> {
|
||||
fn unparsed(&self) -> &Unparsed {
|
||||
self.inner.unparsed()
|
||||
}
|
||||
|
||||
impl<Kind> UnparsedMut for Collection<Kind> {
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||||
self.inner.unparsed_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> WithUnparsed for CollectionPage<Kind> {
|
||||
fn unparsed(&self) -> &Unparsed {
|
||||
self.inner.unparsed()
|
||||
}
|
||||
|
||||
impl<Kind> UnparsedMut for CollectionPage<Kind> {
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||||
self.inner.unparsed_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl WithUnparsed for OrderedCollectionPage {
|
||||
fn unparsed(&self) -> &Unparsed {
|
||||
self.inner.unparsed()
|
||||
}
|
||||
|
||||
impl UnparsedMut for OrderedCollectionPage {
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||||
self.inner.unparsed_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> ObjectRef<Kind> for Collection<Kind> {
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
impl<Kind> ObjectMut<Kind> for Collection<Kind> {
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> CollectionRef<Kind> for Collection<Kind> {
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl<Kind> CollectionMut<Kind> for Collection<Kind> {
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> ObjectRef<Kind> for CollectionPage<Kind> {
|
||||
fn object_ref(&self) -> &Object<Kind> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
}
|
||||
impl<Kind> ObjectMut<Kind> for CollectionPage<Kind> {
|
||||
fn object_mut(&mut self) -> &mut Object<Kind> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> CollectionRef<Kind> for CollectionPage<Kind> {
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
impl<Kind> CollectionMut<Kind> for CollectionPage<Kind> {
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<Kind> CollectionPageRef<Kind> for CollectionPage<Kind> {
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl<Kind> CollectionPageMut<Kind> for CollectionPage<Kind> {
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRef<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn object_ref(&self) -> &Object<OrderedCollectionPageType> {
|
||||
self.inner.object_ref()
|
||||
}
|
||||
}
|
||||
impl ObjectMut<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn object_mut(&mut self) -> &mut Object<OrderedCollectionPageType> {
|
||||
self.inner.object_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectionRef<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn collection_ref(&self) -> &Collection<OrderedCollectionPageType> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
}
|
||||
impl CollectionMut<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn collection_mut(&mut self) -> &mut Collection<OrderedCollectionPageType> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectionPageRef<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn collection_page_ref(&self) -> &CollectionPage<OrderedCollectionPageType> {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
impl CollectionPageMut<OrderedCollectionPageType> for OrderedCollectionPage {
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<OrderedCollectionPageType> {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner> traits::Collection for ApObject<Inner> where Inner: traits::Collection {}
|
||||
impl<Inner> traits::CollectionPage for ApObject<Inner> where Inner: traits::CollectionPage {}
|
||||
|
||||
impl<Inner, Kind> CollectionRef<Kind> for ApObject<Inner>
|
||||
where
|
||||
Inner: CollectionRef<Kind>,
|
||||
{
|
||||
fn collection_ref(&self) -> &Collection<Kind> {
|
||||
self.inner.collection_ref()
|
||||
}
|
||||
}
|
||||
impl<Inner, Kind> CollectionMut<Kind> for ApObject<Inner>
|
||||
where
|
||||
Inner: CollectionMut<Kind>,
|
||||
{
|
||||
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
||||
self.inner.collection_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner, Kind> CollectionPageRef<Kind> for ApObject<Inner>
|
||||
where
|
||||
Inner: CollectionPageRef<Kind>,
|
||||
{
|
||||
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
||||
self.inner.collection_page_ref()
|
||||
}
|
||||
}
|
||||
impl<Inner, Kind> CollectionPageMut<Kind> for ApObject<Inner>
|
||||
where
|
||||
Inner: CollectionPageMut<Kind>,
|
||||
{
|
||||
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
||||
self.inner.collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Inner> OrderedCollectionPageRef for ApObject<Inner>
|
||||
where
|
||||
Inner: OrderedCollectionPageRef,
|
||||
{
|
||||
fn ordered_collection_page_ref(&self) -> &OrderedCollectionPage {
|
||||
self.inner.ordered_collection_page_ref()
|
||||
}
|
||||
}
|
||||
impl<Inner> OrderedCollectionPageMut for ApObject<Inner>
|
||||
where
|
||||
Inner: OrderedCollectionPageMut,
|
||||
{
|
||||
fn ordered_collection_page_mut(&mut self) -> &mut OrderedCollectionPage {
|
||||
self.inner.ordered_collection_page_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Kind> CollectionRefExt<Kind> for T where T: CollectionRef<Kind> {}
|
||||
impl<T, Kind> CollectionMutExt<Kind> for T where T: CollectionMut<Kind> {}
|
||||
|
||||
impl<T, Kind> CollectionPageRefExt<Kind> for T where T: CollectionPageRef<Kind> {}
|
||||
impl<T, Kind> CollectionPageMutExt<Kind> for T where T: CollectionPageMut<Kind> {}
|
||||
|
||||
impl<T> OrderedCollectionPageRefExt for T where T: OrderedCollectionPageRef {}
|
||||
impl<T> OrderedCollectionPageMutExt for T where T: OrderedCollectionPageMut {}
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -7,3 +7,23 @@ pub mod primitives;
|
|||
pub mod traits;
|
||||
|
||||
pub use activitystreams::{context, public, security};
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{
|
||||
activity::{
|
||||
ActivityMutExt, ActivityRefExt, ActorAndObjectMutExt, ActorAndObjectRefExt,
|
||||
OptOriginMutExt, OptOriginRefExt, OptTargetMutExt, OptTargetRefExt, OriginMutExt,
|
||||
OriginRefExt, QuestionMutExt, QuestionRefExt, TargetMutExt, TargetRefExt,
|
||||
},
|
||||
actor::{ApActorMutExt, ApActorRefExt},
|
||||
collection::{
|
||||
CollectionMutExt, CollectionPageMutExt, CollectionPageRefExt, CollectionRefExt,
|
||||
OrderedCollectionPageMutExt, OrderedCollectionPageRefExt,
|
||||
},
|
||||
object::{
|
||||
ApObjectMutExt, ApObjectRefExt, ObjectMutExt, ObjectRefExt, PlaceRefExt, ProfileMutExt,
|
||||
ProfileRefExt, RelationshipMutExt, RelationshipRefExt, TombstoneMutExt,
|
||||
TombstoneRefExt,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
1916
src/object.rs
1916
src/object.rs
File diff suppressed because it is too large
Load diff
|
@ -187,16 +187,24 @@ impl<T> OneOrMany<T> {
|
|||
|
||||
impl crate::traits::Base for Unparsed {}
|
||||
|
||||
impl crate::traits::WithUnparsed for Unparsed {
|
||||
fn unparsed(&self) -> &Unparsed {
|
||||
self
|
||||
}
|
||||
|
||||
impl crate::traits::UnparsedMut for Unparsed {
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<T> for OneOrMany<T> {
|
||||
fn from(t: T) -> Self {
|
||||
OneOrMany::from_one(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Vec<T>> for OneOrMany<T> {
|
||||
fn from(t: Vec<T>) -> Self {
|
||||
OneOrMany::from_many(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<XsdString> for AnyString {
|
||||
fn from(s: XsdString) -> Self {
|
||||
AnyString::from_xsd_string(s)
|
||||
|
|
|
@ -3,13 +3,11 @@ pub use activitystreams::{
|
|||
Activity, Actor, Base, Collection, CollectionPage, IntransitiveActivity, Link, Object,
|
||||
};
|
||||
|
||||
pub trait WithUnparsed {
|
||||
fn unparsed(&self) -> &Unparsed;
|
||||
|
||||
pub trait UnparsedMut {
|
||||
fn unparsed_mut(&mut self) -> &mut Unparsed;
|
||||
}
|
||||
|
||||
pub trait WithUnparsedExt: WithUnparsed {
|
||||
pub trait UnparsedMutExt: UnparsedMut {
|
||||
fn remove<T>(&mut self, key: &str) -> Result<T, serde_json::Error>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
|
@ -35,4 +33,4 @@ pub trait Extends<T>: Sized {
|
|||
fn retracts(self) -> Result<T, Self::Error>;
|
||||
}
|
||||
|
||||
impl<T> WithUnparsedExt for T where T: WithUnparsed {}
|
||||
impl<T> UnparsedMutExt for T where T: UnparsedMut {}
|
||||
|
|
Loading…
Reference in a new issue