mirror of
https://git.asonix.dog/asonix/activitystreams.git
synced 2024-11-28 23:01:01 +00:00
Make items optional in a collection
This commit is contained in:
parent
30af390078
commit
bbbae3d951
4 changed files with 126 additions and 95 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "activitystreams"
|
name = "activitystreams"
|
||||||
description = "A set of core types and traits for activitystreams data"
|
description = "A set of core types and traits for activitystreams data"
|
||||||
version = "0.7.0-alpha.0"
|
version = "0.7.0-alpha.1"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
repository = "https://git.asonix.dog/Aardwolf/activitystreams"
|
||||||
|
|
|
@ -47,10 +47,9 @@ fn main() -> Result<(), Error> {
|
||||||
println!("{:#?}", collection);
|
println!("{:#?}", collection);
|
||||||
|
|
||||||
let v: Vec<ApObject<Page>> = collection
|
let v: Vec<ApObject<Page>> = collection
|
||||||
.items()
|
.take_items()
|
||||||
.clone()
|
|
||||||
.many()
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.map(|o| o.many().into_iter().flatten())
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter_map(|any_base| any_base.take_base())
|
.filter_map(|any_base| any_base.take_base())
|
||||||
.map(|base| base.solidify().and_then(|o| o.extend()))
|
.map(|base| base.solidify().and_then(|o| o.extend()))
|
||||||
|
|
|
@ -9,11 +9,10 @@
|
||||||
//! uri,
|
//! uri,
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! let mut collection = OrderedCollection::new(vec![
|
//! let mut collection = OrderedCollection::new();
|
||||||
//! uri!("https://example.com/notes/1234").into(),
|
|
||||||
//! ]);
|
|
||||||
//!
|
//!
|
||||||
//! collection
|
//! collection
|
||||||
|
//! .set_items(uri!("https://example.com/notes/1234"))
|
||||||
//! .set_total_items(1u64)
|
//! .set_total_items(1u64)
|
||||||
//! .set_current(uri!("https://example.com/notes/1234"))
|
//! .set_current(uri!("https://example.com/notes/1234"))
|
||||||
//! .set_first(uri!("https://example.com/notes/1234"))
|
//! .set_first(uri!("https://example.com/notes/1234"))
|
||||||
|
@ -83,19 +82,19 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Fetch the items for the current activity
|
/// Fetch the items for the current activity
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// let items_ref = collection.items();
|
/// let items_ref = collection.items();
|
||||||
/// println!("{:?}", items_ref);
|
/// println!("{:?}", items_ref);
|
||||||
/// ```
|
/// ```
|
||||||
fn items<'a>(&'a self) -> &'a OneOrMany<AnyBase>
|
fn items<'a>(&'a self) -> Option<&'a OneOrMany<AnyBase>>
|
||||||
where
|
where
|
||||||
Kind: 'a,
|
Kind: 'a,
|
||||||
{
|
{
|
||||||
&self.collection_ref().items
|
self.collection_ref().items.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the items for the current activity
|
/// Set the items for the current activity
|
||||||
|
@ -105,8 +104,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_items(uri!("https://example.com"));
|
/// collection.set_items(uri!("https://example.com"));
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
|
@ -116,7 +115,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
where
|
where
|
||||||
T: Into<AnyBase>,
|
T: Into<AnyBase>,
|
||||||
{
|
{
|
||||||
self.collection_mut().items = item.into().into();
|
self.collection_mut().items = Some(item.into().into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +126,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection.set_many_items(vec![
|
/// collection.set_many_items(vec![
|
||||||
/// uri!("https://example.com/one"),
|
/// uri!("https://example.com/one"),
|
||||||
|
@ -143,7 +142,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
T: Into<AnyBase>,
|
T: Into<AnyBase>,
|
||||||
{
|
{
|
||||||
let v: Vec<_> = items.into_iter().map(Into::into).collect();
|
let v: Vec<_> = items.into_iter().map(Into::into).collect();
|
||||||
self.collection_mut().items = v.into();
|
self.collection_mut().items = Some(v.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +153,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
///
|
///
|
||||||
/// collection
|
/// collection
|
||||||
/// .add_items(uri!("https://example.com/one"))
|
/// .add_items(uri!("https://example.com/one"))
|
||||||
|
@ -167,15 +166,53 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
where
|
where
|
||||||
T: Into<AnyBase>,
|
T: Into<AnyBase>,
|
||||||
{
|
{
|
||||||
self.collection_mut().items.add(item.into());
|
match self.collection_mut().items {
|
||||||
|
Some(ref mut items) => {
|
||||||
|
items.add(item.into());
|
||||||
|
}
|
||||||
|
None => self.collection_mut().items = Some(item.into().into()),
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Take the items of the current object, leaving nothing
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
|
/// use activitystreams::prelude::*;
|
||||||
|
///
|
||||||
|
/// if let Some(items) = collection.take_items() {
|
||||||
|
/// println!("{:?}", items);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
fn take_items(&mut self) -> Option<OneOrMany<AnyBase>> {
|
||||||
|
self.collection_mut().items.take()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete the items from the current object
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use activitystreams::{context, collection::UnorderedCollection};
|
||||||
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
|
/// # collection.set_items(context());
|
||||||
|
/// use activitystreams::prelude::*;
|
||||||
|
///
|
||||||
|
/// assert!(collection.items().is_some());
|
||||||
|
/// collection.delete_items();
|
||||||
|
/// assert!(collection.items().is_none());
|
||||||
|
/// ```
|
||||||
|
fn delete_items(&mut self) -> &mut Self {
|
||||||
|
self.collection_mut().items = None;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch the total_items of the current object
|
/// Fetch the total_items of the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(total_items) = collection.total_items() {
|
/// if let Some(total_items) = collection.total_items() {
|
||||||
|
@ -194,8 +231,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// This overwrites the contents of total_items
|
/// This overwrites the contents of total_items
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// collection.set_total_items(5u64);
|
/// collection.set_total_items(5u64);
|
||||||
|
@ -211,11 +248,11 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Take the total_items of the current object, leaving nothing
|
/// Take the total_items of the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(total_items) = collection.total_items() {
|
/// if let Some(total_items) = collection.take_total_items() {
|
||||||
/// println!("{:?}", total_items);
|
/// println!("{:?}", total_items);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -226,8 +263,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Delete the total_items from the current object
|
/// Delete the total_items from the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// # collection.set_total_items(5u64);
|
/// # collection.set_total_items(5u64);
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -243,8 +280,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Fetch the current field for the current object
|
/// Fetch the current field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -265,8 +302,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection, uri};
|
/// # use activitystreams::{collection::UnorderedCollection, uri};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -285,8 +322,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Take the current field from the current object, leaving nothing
|
/// Take the current field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -302,7 +339,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{context, collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// # collection.set_current(context());
|
/// # collection.set_current(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -319,8 +356,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Fetch the first field for the current object
|
/// Fetch the first field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -341,8 +378,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, uri};
|
||||||
///
|
///
|
||||||
|
@ -361,8 +398,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Take the first field from the current object, leaving nothing
|
/// Take the first field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -378,7 +415,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{context, collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// # collection.set_first(context());
|
/// # collection.set_first(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -395,8 +432,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Fetch the last field for the current object
|
/// Fetch the last field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -417,8 +454,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, uri};
|
||||||
///
|
///
|
||||||
|
@ -437,8 +474,8 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
/// Take the last field from the current object, leaving nothing
|
/// Take the last field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -454,7 +491,7 @@ pub trait CollectionExt<Kind>: AsCollection<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollection};
|
/// # use activitystreams::{context, collection::UnorderedCollection};
|
||||||
/// # let mut collection = UnorderedCollection::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollection::new();
|
||||||
/// # collection.set_last(context());
|
/// # collection.set_last(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -479,8 +516,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Fetch the part_of field for the current object
|
/// Fetch the part_of field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -501,8 +538,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, uri};
|
||||||
///
|
///
|
||||||
|
@ -521,8 +558,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Take the part_of field from the current object, leaving nothing
|
/// Take the part_of field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -538,7 +575,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// # collection.set_part_of(context());
|
/// # collection.set_part_of(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -555,8 +592,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Fetch the next field for the current object
|
/// Fetch the next field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -577,8 +614,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, uri};
|
||||||
///
|
///
|
||||||
|
@ -597,8 +634,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Take the next field from the current object, leaving nothing
|
/// Take the next field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -614,7 +651,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// # collection.set_next(context());
|
/// # collection.set_next(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -631,8 +668,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Fetch the prev field for the current object
|
/// Fetch the prev field for the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -653,8 +690,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # fn main() -> Result<(), anyhow::Error> {
|
/// # fn main() -> Result<(), anyhow::Error> {
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::{prelude::*, uri};
|
/// use activitystreams::{prelude::*, uri};
|
||||||
///
|
///
|
||||||
|
@ -673,8 +710,8 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
/// Take the prev field from the current object, leaving nothing
|
/// Take the prev field from the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -690,7 +727,7 @@ pub trait CollectionPageExt<Kind>: AsCollectionPage<Kind> {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
/// # use activitystreams::{context, collection::UnorderedCollectionPage};
|
||||||
/// # let mut collection = UnorderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = UnorderedCollectionPage::new();
|
||||||
/// # collection.set_prev(context());
|
/// # collection.set_prev(context());
|
||||||
/// #
|
/// #
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
|
@ -709,8 +746,8 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
|
||||||
/// Fetch the start_index of the current object
|
/// Fetch the start_index of the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::OrderedCollectionPage};
|
/// # use activitystreams::{collection::OrderedCollectionPage};
|
||||||
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = OrderedCollectionPage::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(start_index) = collection.start_index() {
|
/// if let Some(start_index) = collection.start_index() {
|
||||||
|
@ -726,8 +763,8 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
|
||||||
/// This overwrites the contents of start_index
|
/// This overwrites the contents of start_index
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::OrderedCollectionPage};
|
/// # use activitystreams::{collection::OrderedCollectionPage};
|
||||||
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = OrderedCollectionPage::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// collection.set_start_index(5u64);
|
/// collection.set_start_index(5u64);
|
||||||
|
@ -743,8 +780,8 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
|
||||||
/// Take the start_index of the current object, leaving nothing
|
/// Take the start_index of the current object, leaving nothing
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::OrderedCollectionPage};
|
/// # use activitystreams::{collection::OrderedCollectionPage};
|
||||||
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = OrderedCollectionPage::new();
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
/// if let Some(start_index) = collection.start_index() {
|
/// if let Some(start_index) = collection.start_index() {
|
||||||
|
@ -758,8 +795,8 @@ pub trait OrderedCollectionPageExt: AsOrderedCollectionPage {
|
||||||
/// Delete the start_index from the current object
|
/// Delete the start_index from the current object
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use activitystreams::{context, collection::OrderedCollectionPage};
|
/// # use activitystreams::{collection::OrderedCollectionPage};
|
||||||
/// # let mut collection = OrderedCollectionPage::new(vec![context().into()]);
|
/// # let mut collection = OrderedCollectionPage::new();
|
||||||
/// # collection.set_start_index(5u64);
|
/// # collection.set_start_index(5u64);
|
||||||
/// use activitystreams::prelude::*;
|
/// use activitystreams::prelude::*;
|
||||||
///
|
///
|
||||||
|
@ -806,7 +843,7 @@ pub struct Collection<Kind> {
|
||||||
///
|
///
|
||||||
/// - Range: Object | Link | Ordered List of [ Object | Link ]
|
/// - Range: Object | Link | Ordered List of [ Object | Link ]
|
||||||
/// - Functional: false
|
/// - Functional: false
|
||||||
items: OneOrMany<AnyBase>,
|
items: Option<OneOrMany<AnyBase>>,
|
||||||
|
|
||||||
/// A non-negative integer specifying the total number of objects contained by the logical view
|
/// A non-negative integer specifying the total number of objects contained by the logical view
|
||||||
/// of the collection.
|
/// of the collection.
|
||||||
|
@ -903,15 +940,14 @@ impl<Kind> Collection<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use activitystreams::collection::Collection;
|
/// use activitystreams::collection::Collection;
|
||||||
///
|
///
|
||||||
/// let collection = Collection::<String>::new(vec![]);
|
/// let collection = Collection::<String>::new();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T>(items: T) -> Self
|
pub fn new() -> Self
|
||||||
where
|
where
|
||||||
T: Into<OneOrMany<AnyBase>>,
|
|
||||||
Kind: Default,
|
Kind: Default,
|
||||||
{
|
{
|
||||||
Collection {
|
Collection {
|
||||||
items: items.into(),
|
items: None,
|
||||||
total_items: None,
|
total_items: None,
|
||||||
current: None,
|
current: None,
|
||||||
first: None,
|
first: None,
|
||||||
|
@ -964,18 +1000,17 @@ impl<Kind> CollectionPage<Kind> {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use activitystreams::collection::CollectionPage;
|
/// use activitystreams::collection::CollectionPage;
|
||||||
///
|
///
|
||||||
/// let collection = CollectionPage::<String>::new(vec![]);
|
/// let collection = CollectionPage::<String>::new();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T>(items: T) -> Self
|
pub fn new() -> Self
|
||||||
where
|
where
|
||||||
T: Into<OneOrMany<AnyBase>>,
|
|
||||||
Kind: Default,
|
Kind: Default,
|
||||||
{
|
{
|
||||||
CollectionPage {
|
CollectionPage {
|
||||||
part_of: None,
|
part_of: None,
|
||||||
next: None,
|
next: None,
|
||||||
prev: None,
|
prev: None,
|
||||||
inner: Collection::new(items),
|
inner: Collection::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1017,15 +1052,12 @@ impl OrderedCollectionPage {
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use activitystreams::collection::OrderedCollectionPage;
|
/// use activitystreams::collection::OrderedCollectionPage;
|
||||||
///
|
///
|
||||||
/// let collection = OrderedCollectionPage::new(vec![]);
|
/// let collection = OrderedCollectionPage::new();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn new<T>(items: T) -> Self
|
pub fn new() -> Self {
|
||||||
where
|
|
||||||
T: Into<OneOrMany<AnyBase>>,
|
|
||||||
{
|
|
||||||
OrderedCollectionPage {
|
OrderedCollectionPage {
|
||||||
start_index: None,
|
start_index: None,
|
||||||
inner: CollectionPage::new(items),
|
inner: CollectionPage::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,7 @@
|
||||||
//!
|
//!
|
||||||
//! You should have received a copy of the GNU General Public License along with ActivityStreams. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
//! You should have received a copy of the GNU General Public License along with ActivityStreams. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/activitystreams/0.7.0-alpha.0/activitystreams")]
|
#![doc(html_root_url = "https://docs.rs/activitystreams/0.7.0-alpha.1/activitystreams")]
|
||||||
|
|
||||||
pub mod activity;
|
pub mod activity;
|
||||||
pub mod actor;
|
pub mod actor;
|
||||||
|
|
Loading…
Reference in a new issue