activitystreams_types/collection/properties.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 properties of standard collection types
21//!
22//! To use these properties in your own types, you can flatten them into your struct with serde:
23//!
24//! ```rust
25//! use activitystreams_traits::{Collection, Object};
26//! use activitystreams_types::{
27//! collection::properties::CollectionProperties,
28//! object::properties::ObjectProperties,
29//! };
30//! use serde_derive::{Deserialize, Serialize};
31//!
32//! #[derive(Clone, Debug, Serialize, Deserialize)]
33//! #[serde(rename_all = "camelCase")]
34//! pub struct MyCollection {
35//! #[serde(rename = "type")]
36//! pub kind: String,
37//!
38//! /// Define a require property for the MyCollection type
39//! pub my_property: String,
40//!
41//! #[serde(flatten)]
42//! pub object_properties: ObjectProperties,
43//!
44//! #[serde(flatten)]
45//! pub collection_properties: CollectionProperties,
46//! }
47//!
48//! impl Object for MyCollection {}
49//! impl Collection for MyCollection {}
50//! #
51//! # fn main() {}
52//! ```
53
54use activitystreams_derive::Properties;
55use activitystreams_traits::{Collection, CollectionPage, Link, Object};
56use serde_derive::{Deserialize, Serialize};
57
58/// `Collection` objects are a specialization of the base `Object` that serve as a container for
59/// other `Objects` or `Links`.
60///
61/// The items within a `Collection` can be ordered or unordered. The `OrderedCollection` type MAY be
62/// used to identify a `Collection` whose items are always ordered. In the JSON serialization, the
63/// unordered items of a `Collection` are represented using the `items` property while ordered items
64/// are represented using the `ordered_items` property.
65#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
66#[serde(rename_all = "camelCase")]
67pub struct CollectionProperties {
68 /// Identifies the items contained in a collection. The items might be ordered or unordered.
69 ///
70 /// - Range: `Object` | `Link` | Ordered List of [ `Object` | `Link` ]
71 /// - Functional: false
72 #[activitystreams(ab(Object, Link), concrete(String))]
73 pub items: serde_json::Value,
74
75 /// A non-negative integer specifying the total number of objects contained by the logical view
76 /// of the collection.
77 ///
78 /// This number might not reflect the actual number of items serialized within the `Collection`
79 /// object instance.
80 ///
81 /// - Range: `xsd:nonNegativeInteger`
82 /// - Functional: true
83 #[serde(skip_serializing_if = "Option::is_none")]
84 #[activitystreams(concrete(u64), functional)]
85 pub total_items: Option<serde_json::Value>,
86
87 /// In a paged `Collection`, indicates the page that contains the most recently updated member
88 /// items.
89 ///
90 /// - Range: `CollectionPage` | `Link`
91 /// - Functional: true
92 #[serde(skip_serializing_if = "Option::is_none")]
93 #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)]
94 pub current: Option<serde_json::Value>,
95
96 /// In a paged `Collection`, indicates the furthest preceeding page of items in the collection.
97 ///
98 /// - Range: `CollectionPage` | `Link`
99 /// - Functional: true
100 #[serde(skip_serializing_if = "Option::is_none")]
101 #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)]
102 pub first: Option<serde_json::Value>,
103
104 /// In a paged `Collection`, indicates the furthest proceeding page of the collection.
105 ///
106 /// - Range: `CollectionPage` | `Link`
107 /// - Functional: true
108 #[serde(skip_serializing_if = "Option::is_none")]
109 #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)]
110 pub last: Option<serde_json::Value>,
111}
112
113/// The `CollectionPage` type extends from the base `Collection` type and inherits all of it's
114/// properties.
115#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
116#[serde(rename_all = "camelCase")]
117pub struct CollectionPageProperties {
118 /// Identifies the `Collection` to which a `CollectionPage` objects items belong.
119 ///
120 /// Range: `Collection` | `Link`
121 /// Functional: true
122 #[serde(skip_serializing_if = "Option::is_none")]
123 #[activitystreams(ab(Link, Collection), concrete(String), functional)]
124 pub part_of: Option<serde_json::Value>,
125
126 /// In a paged `Collection`, indicates the next page of items.
127 ///
128 /// - Range: `CollectionPage` | `Link`
129 /// - Functional: true
130 #[serde(skip_serializing_if = "Option::is_none")]
131 #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)]
132 pub next: Option<serde_json::Value>,
133
134 /// In a paged `Collection`, identifies the previous page of items.
135 ///
136 /// - Range: `CollectionPage` | `Link`
137 /// - Functional: true
138 #[serde(skip_serializing_if = "Option::is_none")]
139 #[activitystreams(ab(Link, CollectionPage), concrete(String), functional)]
140 pub prev: Option<serde_json::Value>,
141}
142
143/// The OrderedCollectionPage type MAY be used to identify a page whose items are strictly ordered.
144#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
145#[serde(rename_all = "camelCase")]
146pub struct OrderedCollectionPageProperties {
147 /// A non-negative integer value identifying the relative position within the logical view of a
148 /// strictly ordered collection.
149 ///
150 /// - Range: `xsd:nonNegativeInteger`
151 /// - Functional: true
152 #[serde(skip_serializing_if = "Option::is_none")]
153 #[activitystreams(concrete(u64), functional)]
154 pub start_index: Option<serde_json::Value>,
155}