2020-05-14 03:54:50 +00:00
|
|
|
use crate::{
|
2020-05-15 22:01:29 +00:00
|
|
|
base::{AnyBase, AsBase, Base, Extends},
|
|
|
|
markers,
|
|
|
|
object::{ApObject, AsObject, Object},
|
|
|
|
primitives::{OneOrMany, XsdNonNegativeInteger},
|
|
|
|
unparsed::{Unparsed, UnparsedMut, UnparsedMutExt},
|
2020-05-14 03:54:50 +00:00
|
|
|
};
|
|
|
|
use std::convert::TryFrom;
|
2020-05-14 16:23:38 +00:00
|
|
|
use typed_builder::TypedBuilder;
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
pub mod kind {
|
|
|
|
pub use activitystreams::collection::kind::*;
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
use self::kind::*;
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait AsCollection<Kind>: markers::Collection {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_ref(&self) -> &Collection<Kind>;
|
|
|
|
fn collection_mut(&mut self) -> &mut Collection<Kind>;
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait AsCollectionPage<Kind>: markers::CollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_ref(&self) -> &CollectionPage<Kind>;
|
|
|
|
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind>;
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait AsOrderedCollectionPage: markers::CollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn ordered_collection_page_ref(&self) -> &OrderedCollectionPage;
|
|
|
|
fn ordered_collection_page_mut(&mut self) -> &mut OrderedCollectionPage;
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
|
|
|
fn items<'a>(&'a self) -> &'a OneOrMany<AnyBase>
|
2020-05-15 03:18:34 +00:00
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
&self.collection_ref().items
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_items<T>(&mut self, item: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
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>,
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
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
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_mut().items.add(item.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn total_items<'a>(&'a self) -> Option<&'a XsdNonNegativeInteger>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_ref().total_items.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn current<'a>(&'a self) -> Option<&'a AnyBase>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_ref().current.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn set_current<T>(&mut self, current: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_mut().current = Some(current.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_current(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_mut().current.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_current(&mut self) -> &mut Self {
|
|
|
|
self.collection_mut().current = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn first<'a>(&'a self) -> Option<&'a AnyBase>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_ref().first.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn set_first<T>(&mut self, first: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_mut().first = Some(first.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_first(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_mut().first.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_first(&mut self) -> &mut Self {
|
|
|
|
self.collection_mut().first = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn last<'a>(&'a self) -> Option<&'a AnyBase>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_ref().last.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn set_last<T>(&mut self, last: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_mut().last = Some(last.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_last(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_mut().last.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_last(&mut self) -> &mut Self {
|
|
|
|
self.collection_mut().last = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
|
|
|
fn part_of<'a>(&'a self) -> Option<&'a AnyBase>
|
2020-05-15 03:18:34 +00:00
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_page_ref().part_of.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_part_of<T>(&mut self, part_of: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_page_mut().part_of = Some(part_of.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_part_of(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_page_mut().part_of.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_part_of(&mut self) -> &mut Self {
|
|
|
|
self.collection_page_mut().part_of = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn next<'a>(&'a self) -> Option<&'a AnyBase>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_page_ref().next.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn set_next<T>(&mut self, next: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_page_mut().next = Some(next.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_next(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_page_mut().next.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_next(&mut self) -> &mut Self {
|
|
|
|
self.collection_page_mut().next = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn prev<'a>(&'a self) -> Option<&'a AnyBase>
|
|
|
|
where
|
|
|
|
Kind: 'a,
|
|
|
|
{
|
|
|
|
self.collection_page_ref().prev.as_ref()
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn set_prev<T>(&mut self, prev: T) -> &mut Self
|
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
T: Into<AnyBase>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
self.collection_page_mut().prev = Some(prev.into());
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn take_prev(&mut self) -> Option<AnyBase> {
|
2020-05-15 03:18:34 +00:00
|
|
|
self.collection_page_mut().prev.take()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn delete_prev(&mut self) -> &mut Self {
|
|
|
|
self.collection_page_mut().prev = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn start_index(&self) -> Option<&XsdNonNegativeInteger> {
|
|
|
|
self.ordered_collection_page_ref().start_index.as_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 03:54:50 +00:00
|
|
|
pub type OrderedCollection = Collection<OrderedCollectionType>;
|
2020-05-14 16:23:38 +00:00
|
|
|
pub type UnorderedCollection = Collection<CollectionType>;
|
|
|
|
pub type UnorderedCollectionPage = CollectionPage<CollectionPageType>;
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct Collection<Kind> {
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(setter(into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub items: OneOrMany<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
|
|
|
pub total_items: Option<XsdNonNegativeInteger>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub current: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub first: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub last: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Object<Kind>,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct CollectionPage<Kind> {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub part_of: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub next: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-15 22:01:29 +00:00
|
|
|
pub prev: Option<AnyBase>,
|
2020-05-14 03:54:50 +00:00
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: Collection<Kind>,
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:23:38 +00:00
|
|
|
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, TypedBuilder)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(doc)]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub struct OrderedCollectionPage {
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2020-05-14 16:23:38 +00:00
|
|
|
#[builder(default, setter(strip_option, into))]
|
2020-05-14 03:54:50 +00:00
|
|
|
pub start_index: Option<XsdNonNegativeInteger>,
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub inner: CollectionPage<OrderedCollectionPageType>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> Collection<Kind> {
|
|
|
|
fn extending(mut inner: Object<Kind>) -> Result<Self, serde_json::Error> {
|
|
|
|
let items = inner.remove("items")?;
|
|
|
|
let total_items = inner.remove("totalItems")?;
|
|
|
|
let current = inner.remove("current")?;
|
|
|
|
let first = inner.remove("first")?;
|
|
|
|
let last = inner.remove("last")?;
|
|
|
|
|
|
|
|
Ok(Collection {
|
|
|
|
items,
|
|
|
|
total_items,
|
|
|
|
current,
|
|
|
|
first,
|
|
|
|
last,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<Kind>, serde_json::Error> {
|
|
|
|
let Collection {
|
|
|
|
items,
|
|
|
|
total_items,
|
|
|
|
current,
|
|
|
|
first,
|
|
|
|
last,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("last", last)?
|
|
|
|
.insert("first", first)?
|
|
|
|
.insert("current", current)?
|
|
|
|
.insert("totalItems", total_items)?
|
|
|
|
.insert("items", items)?;
|
|
|
|
|
|
|
|
Ok(inner)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> CollectionPage<Kind> {
|
|
|
|
fn extending(object: Object<Kind>) -> Result<Self, serde_json::Error> {
|
|
|
|
let mut inner = Collection::extending(object)?;
|
|
|
|
|
|
|
|
let part_of = inner.remove("partOf")?;
|
|
|
|
let next = inner.remove("next")?;
|
|
|
|
let prev = inner.remove("prev")?;
|
|
|
|
|
|
|
|
Ok(CollectionPage {
|
|
|
|
part_of,
|
|
|
|
next,
|
|
|
|
prev,
|
|
|
|
inner,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<Kind>, serde_json::Error> {
|
|
|
|
let CollectionPage {
|
|
|
|
part_of,
|
|
|
|
next,
|
|
|
|
prev,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner
|
|
|
|
.insert("prev", prev)?
|
|
|
|
.insert("next", next)?
|
|
|
|
.insert("partOf", part_of)?;
|
|
|
|
|
|
|
|
inner.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OrderedCollectionPage {
|
|
|
|
fn extending(object: Object<OrderedCollectionPageType>) -> Result<Self, serde_json::Error> {
|
|
|
|
let mut inner = CollectionPage::extending(object)?;
|
|
|
|
|
|
|
|
let start_index = inner.remove("startIndex")?;
|
|
|
|
|
|
|
|
Ok(OrderedCollectionPage { start_index, inner })
|
|
|
|
}
|
|
|
|
|
|
|
|
fn retracting(self) -> Result<Object<OrderedCollectionPageType>, serde_json::Error> {
|
|
|
|
let OrderedCollectionPage {
|
|
|
|
start_index,
|
|
|
|
mut inner,
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
inner.insert("startIndex", start_index)?;
|
|
|
|
|
|
|
|
inner.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> markers::Base for Collection<Kind> {}
|
|
|
|
impl<Kind> markers::Object for Collection<Kind> {}
|
|
|
|
impl<Kind> markers::Collection for Collection<Kind> {}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> markers::Base for CollectionPage<Kind> {}
|
|
|
|
impl<Kind> markers::Object for CollectionPage<Kind> {}
|
|
|
|
impl<Kind> markers::Collection for CollectionPage<Kind> {}
|
|
|
|
impl<Kind> markers::CollectionPage for CollectionPage<Kind> {}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl markers::Base for OrderedCollectionPage {}
|
|
|
|
impl markers::Object for OrderedCollectionPage {}
|
|
|
|
impl markers::Collection for OrderedCollectionPage {}
|
|
|
|
impl markers::CollectionPage for OrderedCollectionPage {}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> Extends<Kind> for Collection<Kind>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned + serde::ser::Serialize,
|
|
|
|
{
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
let inner = Object::extends(base)?;
|
|
|
|
Self::extending(inner)
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
|
|
|
let inner = self.retracting()?;
|
|
|
|
inner.retracts()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> TryFrom<Collection<Kind>> for Object<Kind> {
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(collection: Collection<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
collection.retracting()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> TryFrom<Object<Kind>> for Collection<Kind> {
|
2020-05-14 16:23:38 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(object: Object<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
Self::extending(object)
|
2020-05-14 16:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> Extends<Kind> for CollectionPage<Kind>
|
|
|
|
where
|
|
|
|
Kind: serde::de::DeserializeOwned + serde::ser::Serialize,
|
|
|
|
{
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn extends(base: Base<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
let inner = Object::extends(base)?;
|
|
|
|
Self::extending(inner)
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn retracts(self) -> Result<Base<Kind>, Self::Error> {
|
|
|
|
let inner = self.retracting()?;
|
|
|
|
inner.retracts()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> TryFrom<Object<Kind>> for CollectionPage<Kind> {
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(object: Object<Kind>) -> Result<Self, Self::Error> {
|
2020-05-14 03:54:50 +00:00
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> TryFrom<CollectionPage<Kind>> for Object<Kind> {
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(collection_page: CollectionPage<Kind>) -> Result<Self, Self::Error> {
|
|
|
|
collection_page.retracting()
|
2020-05-14 16:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl Extends<OrderedCollectionPageType> for OrderedCollectionPage {
|
2020-05-14 16:23:38 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn extends(base: Base<OrderedCollectionPageType>) -> Result<Self, Self::Error> {
|
|
|
|
let inner = Object::extends(base)?;
|
|
|
|
Self::extending(inner)
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
fn retracts(self) -> Result<Base<OrderedCollectionPageType>, Self::Error> {
|
|
|
|
let inner = self.retracting()?;
|
|
|
|
inner.retracts()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl TryFrom<Object<OrderedCollectionPageType>> for OrderedCollectionPage {
|
2020-05-14 03:54:50 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(object: Object<OrderedCollectionPageType>) -> Result<Self, Self::Error> {
|
2020-05-14 03:54:50 +00:00
|
|
|
Self::extending(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl TryFrom<OrderedCollectionPage> for Object<OrderedCollectionPageType> {
|
2020-05-14 16:23:38 +00:00
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn try_from(collection_page: OrderedCollectionPage) -> Result<Self, Self::Error> {
|
2020-05-14 16:23:38 +00:00
|
|
|
collection_page.retracting()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> UnparsedMut for Collection<Kind> {
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl<Kind> UnparsedMut for CollectionPage<Kind> {
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
2020-05-15 03:18:34 +00:00
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
impl UnparsedMut for OrderedCollectionPage {
|
|
|
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
|
|
|
self.inner.unparsed_mut()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> AsBase<Kind> for Collection<Kind> {
|
|
|
|
fn base_ref(&self) -> &Base<Kind> {
|
|
|
|
self.inner.base_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn base_mut(&mut self) -> &mut Base<Kind> {
|
|
|
|
self.inner.base_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> AsObject<Kind> for Collection<Kind> {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_ref(&self) -> &Object<Kind> {
|
|
|
|
&self.inner
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_mut(&mut self) -> &mut Object<Kind> {
|
|
|
|
&mut self.inner
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> AsCollection<Kind> for Collection<Kind> {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_ref(&self) -> &Collection<Kind> {
|
|
|
|
self
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
|
|
|
self
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> AsBase<Kind> for CollectionPage<Kind> {
|
|
|
|
fn base_ref(&self) -> &Base<Kind> {
|
|
|
|
self.inner.base_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn base_mut(&mut self) -> &mut Base<Kind> {
|
|
|
|
self.inner.base_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Kind> AsObject<Kind> for CollectionPage<Kind> {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_ref(&self) -> &Object<Kind> {
|
|
|
|
self.inner.object_ref()
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_mut(&mut self) -> &mut Object<Kind> {
|
|
|
|
self.inner.object_mut()
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 16:23:38 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> AsCollection<Kind> for CollectionPage<Kind> {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_ref(&self) -> &Collection<Kind> {
|
|
|
|
&self.inner
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
|
|
|
&mut self.inner
|
2020-05-14 16:23:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Kind> AsCollectionPage<Kind> for CollectionPage<Kind> {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
|
|
|
self
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
|
|
|
self
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
2020-05-15 03:18:34 +00:00
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl AsBase<OrderedCollectionPageType> for OrderedCollectionPage {
|
|
|
|
fn base_ref(&self) -> &Base<OrderedCollectionPageType> {
|
|
|
|
self.inner.base_ref()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn base_mut(&mut self) -> &mut Base<OrderedCollectionPageType> {
|
|
|
|
self.inner.base_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AsObject<OrderedCollectionPageType> for OrderedCollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_ref(&self) -> &Object<OrderedCollectionPageType> {
|
|
|
|
self.inner.object_ref()
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn object_mut(&mut self) -> &mut Object<OrderedCollectionPageType> {
|
|
|
|
self.inner.object_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl AsCollection<OrderedCollectionPageType> for OrderedCollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_ref(&self) -> &Collection<OrderedCollectionPageType> {
|
|
|
|
self.inner.collection_ref()
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_mut(&mut self) -> &mut Collection<OrderedCollectionPageType> {
|
|
|
|
self.inner.collection_mut()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl AsCollectionPage<OrderedCollectionPageType> for OrderedCollectionPage {
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_ref(&self) -> &CollectionPage<OrderedCollectionPageType> {
|
|
|
|
&self.inner
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_mut(&mut self) -> &mut CollectionPage<OrderedCollectionPageType> {
|
|
|
|
&mut self.inner
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Inner> markers::Collection for ApObject<Inner> where Inner: markers::Collection {}
|
|
|
|
impl<Inner> markers::CollectionPage for ApObject<Inner> where Inner: markers::CollectionPage {}
|
2020-05-15 03:18:34 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Inner, Kind> AsCollection<Kind> for ApObject<Inner>
|
2020-05-15 03:18:34 +00:00
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
Inner: AsCollection<Kind>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
fn collection_ref(&self) -> &Collection<Kind> {
|
|
|
|
self.inner.collection_ref()
|
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_mut(&mut self) -> &mut Collection<Kind> {
|
|
|
|
self.inner.collection_mut()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Inner, Kind> AsCollectionPage<Kind> for ApObject<Inner>
|
2020-05-15 03:18:34 +00:00
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
Inner: AsCollectionPage<Kind>,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
fn collection_page_ref(&self) -> &CollectionPage<Kind> {
|
|
|
|
self.inner.collection_page_ref()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn collection_page_mut(&mut self) -> &mut CollectionPage<Kind> {
|
|
|
|
self.inner.collection_page_mut()
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 03:54:50 +00:00
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<Inner> AsOrderedCollectionPage for ApObject<Inner>
|
2020-05-15 03:18:34 +00:00
|
|
|
where
|
2020-05-15 22:01:29 +00:00
|
|
|
Inner: AsOrderedCollectionPage,
|
2020-05-15 03:18:34 +00:00
|
|
|
{
|
|
|
|
fn ordered_collection_page_ref(&self) -> &OrderedCollectionPage {
|
|
|
|
self.inner.ordered_collection_page_ref()
|
2020-05-14 03:54:50 +00:00
|
|
|
}
|
2020-05-15 22:01:29 +00:00
|
|
|
|
2020-05-15 03:18:34 +00:00
|
|
|
fn ordered_collection_page_mut(&mut self) -> &mut OrderedCollectionPage {
|
|
|
|
self.inner.ordered_collection_page_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 22:01:29 +00:00
|
|
|
impl<T, Kind> CollectionExt<Kind> for T where T: AsCollection<Kind> {}
|
|
|
|
impl<T, Kind> CollectionPageExt<Kind> for T where T: AsCollectionPage<Kind> {}
|
|
|
|
impl<T> OrderedCollectionPageExt for T where T: AsOrderedCollectionPage {}
|