1
0
Fork 0
forked from alemi/upub

feat: getters/setters for collection and page

This commit is contained in:
əlemi 2024-03-20 07:54:14 +01:00
parent 8a4e40c93a
commit 9f06aa5993
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 32 additions and 6 deletions

View file

@ -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 }
}

View file

@ -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 }
}