diff --git a/src/activitystream/object/collection/mod.rs b/src/activitystream/object/collection/mod.rs index 33eb0f83..14bdc2a8 100644 --- a/src/activitystream/object/collection/mod.rs +++ b/src/activitystream/object/collection/mod.rs @@ -2,7 +2,7 @@ pub mod page; pub use page::CollectionPage; use crate::activitystream::Node; -use crate::strenum; +use crate::{getter, setter, strenum}; strenum! { pub enum CollectionType { @@ -16,23 +16,41 @@ strenum! { pub trait Collection : super::Object { fn collection_type(&self) -> Option { None } - fn total_items(&self) -> Option { None } + fn total_items(&self) -> Option { None } fn current(&self) -> Node { Node::Empty:: } fn first(&self) -> Node { Node::Empty:: } fn last(&self) -> Node { Node::Empty:: } fn items(&self) -> Node { Node::Empty:: } + fn ordered_items(&self) -> Node { Node::Empty:: } } pub trait CollectionMut : super::ObjectMut { fn set_collection_type(&mut self, val: Option) -> &mut Self; - fn set_total_items(&mut self, val: Option) -> &mut Self; + fn set_total_items(&mut self, val: Option) -> &mut Self; fn set_current(&mut self, val: Node) -> &mut Self; fn set_first(&mut self, val: Node) -> &mut Self; fn set_last(&mut self, val: Node) -> &mut Self; fn set_items(&mut self, val: Node) -> &mut Self; + fn set_ordered_items(&mut self, val: Node) -> &mut Self; } impl Collection for serde_json::Value { - // ... TODO + getter! { collection_type -> type CollectionType } + getter! { total_items::totalItems -> u64 } + getter! { current -> node impl CollectionPage } + getter! { first -> node impl CollectionPage } + getter! { last -> node impl CollectionPage } + getter! { items -> node impl super::Object } + getter! { ordered_items::orderedItems -> node impl super::Object } +} + +impl CollectionMut for serde_json::Value { + setter! { collection_type -> type CollectionType } + setter! { total_items::totalItems -> u64 } + setter! { current -> node impl CollectionPage } + setter! { first -> node impl CollectionPage } + setter! { last -> node impl CollectionPage } + setter! { items -> node impl super::Object } + setter! { ordered_items::orderedItems -> node impl super::Object } } diff --git a/src/activitystream/object/collection/page.rs b/src/activitystream/object/collection/page.rs index 1d9aa17b..49a36359 100644 --- a/src/activitystream/object/collection/page.rs +++ b/src/activitystream/object/collection/page.rs @@ -1,4 +1,4 @@ -use crate::activitystream::Node; +use crate::{activitystream::Node, getter, setter}; pub trait CollectionPage : super::Collection { fn part_of(&self) -> Node { Node::Empty:: } @@ -13,5 +13,13 @@ pub trait CollectionPageMut : super::CollectionMut { } impl CollectionPage for serde_json::Value { - // ... TODO + getter! { part_of::partOf -> node impl super::Collection } + getter! { next -> node impl CollectionPage } + getter! { prev -> node impl CollectionPage } +} + +impl CollectionPageMut for serde_json::Value { + setter! { part_of::partOf -> node impl super::Collection } + setter! { next -> node impl CollectionPage } + setter! { prev -> node impl CollectionPage } }