activitystreams_types/collection/
mod.rs

1/*
2 * This file is part of ActivityStreams Types.
3 *
4 * Copyright © 2018 Riley Trautman
5 *
6 * ActivityStreams Types is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ActivityStreams Types is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with ActivityStreams Types.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20//! Namespace for Collection types
21
22use activitystreams_derive::Properties;
23use activitystreams_traits::{Collection, CollectionPage, Object};
24use serde_derive::{Deserialize, Serialize};
25
26use crate::object::{properties::ObjectProperties, ObjectExt};
27
28pub mod kind;
29pub mod properties;
30use self::kind::*;
31use self::properties::*;
32
33/// The Collection Extension Trait
34///
35/// This trait provides generic access to a collection's properties
36pub trait CollectionExt: Collection {
37    fn props(&self) -> &CollectionProperties;
38    fn props_mut(&mut self) -> &mut CollectionProperties;
39}
40
41/// The Collection Page Extension Trait
42///
43/// This trait provides generic access to a collection page's properties
44pub trait CollectionPageExt: CollectionPage {
45    fn props(&self) -> &CollectionPageProperties;
46    fn props_mut(&mut self) -> &mut CollectionPageProperties;
47}
48
49/// The default `Collection` type.
50#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
51#[serde(rename_all = "camelCase")]
52pub struct UnorderedCollection {
53    #[serde(rename = "type")]
54    #[serde(alias = "objectType")]
55    #[serde(alias = "verb")]
56    kind: CollectionType,
57
58    /// Adds all valid object properties to this struct
59    #[serde(flatten)]
60    pub object_props: ObjectProperties,
61
62    /// Adds all valid collection properties to this struct
63    #[serde(flatten)]
64    pub collection_props: CollectionProperties,
65}
66
67impl Object for UnorderedCollection {}
68impl ObjectExt for UnorderedCollection {
69    fn props(&self) -> &ObjectProperties {
70        &self.object_props
71    }
72
73    fn props_mut(&mut self) -> &mut ObjectProperties {
74        &mut self.object_props
75    }
76}
77impl Collection for UnorderedCollection {}
78impl CollectionExt for UnorderedCollection {
79    fn props(&self) -> &CollectionProperties {
80        &self.collection_props
81    }
82
83    fn props_mut(&mut self) -> &mut CollectionProperties {
84        &mut self.collection_props
85    }
86}
87
88/// A subtype of `Collection` in which members of the logical collection are assumed to always be
89/// strictly ordered.
90#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
91#[serde(rename_all = "camelCase")]
92pub struct OrderedCollection {
93    #[serde(rename = "type")]
94    #[serde(alias = "objectType")]
95    #[serde(alias = "verb")]
96    kind: OrderedCollectionType,
97
98    /// Adds all valid object properties to this struct
99    #[serde(flatten)]
100    pub object_props: ObjectProperties,
101
102    /// Adds all valid collection properties to this struct
103    #[serde(flatten)]
104    pub collection_props: CollectionProperties,
105}
106
107impl Object for OrderedCollection {}
108impl ObjectExt for OrderedCollection {
109    fn props(&self) -> &ObjectProperties {
110        &self.object_props
111    }
112
113    fn props_mut(&mut self) -> &mut ObjectProperties {
114        &mut self.object_props
115    }
116}
117impl Collection for OrderedCollection {}
118impl CollectionExt for OrderedCollection {
119    fn props(&self) -> &CollectionProperties {
120        &self.collection_props
121    }
122
123    fn props_mut(&mut self) -> &mut CollectionProperties {
124        &mut self.collection_props
125    }
126}
127
128/// Used to represent distinct subsets of items from a `Collection`.
129#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
130#[serde(rename_all = "camelCase")]
131pub struct UnorderedCollectionPage {
132    #[serde(rename = "type")]
133    #[serde(alias = "objectType")]
134    #[serde(alias = "verb")]
135    kind: CollectionPageType,
136
137    /// Adds all valid object properties to this struct
138    #[serde(flatten)]
139    pub object_props: ObjectProperties,
140
141    /// Adds all valid collection properties to this struct
142    #[serde(flatten)]
143    pub collection_props: CollectionProperties,
144
145    /// Adds all valid collection page properties to this struct
146    #[serde(flatten)]
147    pub collection_page_props: CollectionPageProperties,
148}
149
150impl Object for UnorderedCollectionPage {}
151impl ObjectExt for UnorderedCollectionPage {
152    fn props(&self) -> &ObjectProperties {
153        &self.object_props
154    }
155
156    fn props_mut(&mut self) -> &mut ObjectProperties {
157        &mut self.object_props
158    }
159}
160impl Collection for UnorderedCollectionPage {}
161impl CollectionExt for UnorderedCollectionPage {
162    fn props(&self) -> &CollectionProperties {
163        &self.collection_props
164    }
165
166    fn props_mut(&mut self) -> &mut CollectionProperties {
167        &mut self.collection_props
168    }
169}
170impl CollectionPage for UnorderedCollectionPage {}
171impl CollectionPageExt for UnorderedCollectionPage {
172    fn props(&self) -> &CollectionPageProperties {
173        &self.collection_page_props
174    }
175
176    fn props_mut(&mut self) -> &mut CollectionPageProperties {
177        &mut self.collection_page_props
178    }
179}
180
181/// Used to represent ordered subsets of items from an `OrderedCollection`.
182#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
183#[serde(rename_all = "camelCase")]
184pub struct OrderedCollectionPage {
185    #[serde(rename = "type")]
186    #[serde(alias = "objectType")]
187    #[serde(alias = "verb")]
188    kind: OrderedCollectionPageType,
189
190    /// Adds all valid object properties to this struct
191    #[serde(flatten)]
192    pub object_props: ObjectProperties,
193
194    /// Adds all valid collection properties to this struct
195    #[serde(flatten)]
196    pub collection_props: CollectionProperties,
197
198    /// Adds all valid collection page properties to this struct
199    #[serde(flatten)]
200    pub collection_page_props: CollectionPageProperties,
201
202    /// Adds all valid ordered collection page properties to this struct
203    #[serde(flatten)]
204    pub ordered_collection_page_props: OrderedCollectionPageProperties,
205}
206
207impl Object for OrderedCollectionPage {}
208impl ObjectExt for OrderedCollectionPage {
209    fn props(&self) -> &ObjectProperties {
210        &self.object_props
211    }
212
213    fn props_mut(&mut self) -> &mut ObjectProperties {
214        &mut self.object_props
215    }
216}
217impl Collection for OrderedCollectionPage {}
218impl CollectionExt for OrderedCollectionPage {
219    fn props(&self) -> &CollectionProperties {
220        &self.collection_props
221    }
222
223    fn props_mut(&mut self) -> &mut CollectionProperties {
224        &mut self.collection_props
225    }
226}
227impl CollectionPage for OrderedCollectionPage {}
228impl CollectionPageExt for OrderedCollectionPage {
229    fn props(&self) -> &CollectionPageProperties {
230        &self.collection_page_props
231    }
232
233    fn props_mut(&mut self) -> &mut CollectionPageProperties {
234        &mut self.collection_page_props
235    }
236}