forked from alemi/upub
feat: getters/setters for collection and page
This commit is contained in:
parent
8a4e40c93a
commit
9f06aa5993
2 changed files with 32 additions and 6 deletions
|
@ -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<CollectionType> { None }
|
||||
|
||||
fn total_items(&self) -> Option<u32> { None }
|
||||
fn total_items(&self) -> Option<u64> { None }
|
||||
fn current(&self) -> Node<impl CollectionPage> { Node::Empty::<serde_json::Value> }
|
||||
fn first(&self) -> Node<impl CollectionPage> { Node::Empty::<serde_json::Value> }
|
||||
fn last(&self) -> Node<impl CollectionPage> { Node::Empty::<serde_json::Value> }
|
||||
fn items(&self) -> Node<impl super::Object> { Node::Empty::<serde_json::Value> }
|
||||
fn ordered_items(&self) -> Node<impl super::Object> { Node::Empty::<serde_json::Value> }
|
||||
}
|
||||
|
||||
pub trait CollectionMut : super::ObjectMut {
|
||||
fn set_collection_type(&mut self, val: Option<CollectionType>) -> &mut Self;
|
||||
|
||||
fn set_total_items(&mut self, val: Option<u32>) -> &mut Self;
|
||||
fn set_total_items(&mut self, val: Option<u64>) -> &mut Self;
|
||||
fn set_current(&mut self, val: Node<impl CollectionPage>) -> &mut Self;
|
||||
fn set_first(&mut self, val: Node<impl CollectionPage>) -> &mut Self;
|
||||
fn set_last(&mut self, val: Node<impl CollectionPage>) -> &mut Self;
|
||||
fn set_items(&mut self, val: Node<impl super::Object>) -> &mut Self;
|
||||
fn set_ordered_items(&mut self, val: Node<impl super::Object>) -> &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 }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::activitystream::Node;
|
||||
use crate::{activitystream::Node, getter, setter};
|
||||
|
||||
pub trait CollectionPage : super::Collection {
|
||||
fn part_of(&self) -> Node<impl super::Collection> { Node::Empty::<serde_json::Value> }
|
||||
|
@ -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 }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue