activitystreams_types/object/
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 Object types
21
22use activitystreams_derive::Properties;
23use activitystreams_traits::Object;
24use serde_derive::{Deserialize, Serialize};
25
26pub mod kind;
27pub mod properties;
28use self::kind::*;
29use self::properties::*;
30
31/// The Object Extension Trait
32///
33/// This trait provides generic access to an object's properties
34pub trait ObjectExt: Object {
35    fn props(&self) -> &ObjectProperties;
36    fn props_mut(&mut self) -> &mut ObjectProperties;
37}
38
39/// Represents any kind of multi-paragraph written work.
40#[derive(Clone, Debug, Default, Deserialize, Serialize)]
41#[serde(rename_all = "camelCase")]
42pub struct Article {
43    #[serde(rename = "type")]
44    #[serde(alias = "objectType")]
45    #[serde(alias = "verb")]
46    kind: ArticleType,
47
48    /// Adds all valid object properties to this struct
49    #[serde(flatten)]
50    pub object_props: ObjectProperties,
51}
52
53impl Object for Article {}
54impl ObjectExt for Article {
55    fn props(&self) -> &ObjectProperties {
56        &self.object_props
57    }
58
59    fn props_mut(&mut self) -> &mut ObjectProperties {
60        &mut self.object_props
61    }
62}
63
64/// Represents an audio document of any kind.
65#[derive(Clone, Debug, Default, Deserialize, Serialize)]
66#[serde(rename_all = "camelCase")]
67pub struct Audio {
68    #[serde(rename = "type")]
69    #[serde(alias = "objectType")]
70    #[serde(alias = "verb")]
71    kind: AudioType,
72
73    /// Adds all valid object properties to this struct
74    #[serde(flatten)]
75    pub object_props: ObjectProperties,
76}
77
78impl Object for Audio {}
79impl ObjectExt for Audio {
80    fn props(&self) -> &ObjectProperties {
81        &self.object_props
82    }
83
84    fn props_mut(&mut self) -> &mut ObjectProperties {
85        &mut self.object_props
86    }
87}
88
89/// Represents a document of any kind.
90#[derive(Clone, Debug, Default, Deserialize, Serialize)]
91#[serde(rename_all = "camelCase")]
92pub struct Document {
93    #[serde(rename = "type")]
94    #[serde(alias = "objectType")]
95    #[serde(alias = "verb")]
96    kind: DocumentType,
97
98    /// Adds all valid object properties to this struct
99    #[serde(flatten)]
100    pub object_props: ObjectProperties,
101}
102
103impl Object for Document {}
104impl ObjectExt for Document {
105    fn props(&self) -> &ObjectProperties {
106        &self.object_props
107    }
108
109    fn props_mut(&mut self) -> &mut ObjectProperties {
110        &mut self.object_props
111    }
112}
113
114/// Represents any kind of event.
115#[derive(Clone, Debug, Default, Deserialize, Serialize)]
116#[serde(rename_all = "camelCase")]
117pub struct Event {
118    #[serde(rename = "type")]
119    #[serde(alias = "objectType")]
120    #[serde(alias = "verb")]
121    kind: EventType,
122
123    /// Adds all valid object properties to this struct
124    #[serde(flatten)]
125    pub object_props: ObjectProperties,
126}
127
128impl Object for Event {}
129impl ObjectExt for Event {
130    fn props(&self) -> &ObjectProperties {
131        &self.object_props
132    }
133
134    fn props_mut(&mut self) -> &mut ObjectProperties {
135        &mut self.object_props
136    }
137}
138
139/// An image document of any kind
140#[derive(Clone, Debug, Default, Deserialize, Serialize)]
141#[serde(rename_all = "camelCase")]
142pub struct Image {
143    #[serde(rename = "type")]
144    #[serde(alias = "objectType")]
145    #[serde(alias = "verb")]
146    kind: ImageType,
147
148    /// Adds all valid object properties to this struct
149    #[serde(flatten)]
150    pub object_props: ObjectProperties,
151}
152
153impl Object for Image {}
154impl ObjectExt for Image {
155    fn props(&self) -> &ObjectProperties {
156        &self.object_props
157    }
158
159    fn props_mut(&mut self) -> &mut ObjectProperties {
160        &mut self.object_props
161    }
162}
163
164/// Represents a short written work typically less than a single paragraph in length.
165#[derive(Clone, Debug, Default, Deserialize, Serialize)]
166#[serde(rename_all = "camelCase")]
167pub struct Note {
168    #[serde(rename = "type")]
169    #[serde(alias = "objectType")]
170    #[serde(alias = "verb")]
171    kind: NoteType,
172
173    /// Adds all valid object properties to this struct
174    #[serde(flatten)]
175    pub object_props: ObjectProperties,
176}
177
178impl Object for Note {}
179impl ObjectExt for Note {
180    fn props(&self) -> &ObjectProperties {
181        &self.object_props
182    }
183
184    fn props_mut(&mut self) -> &mut ObjectProperties {
185        &mut self.object_props
186    }
187}
188
189/// Represents a Web Page.
190#[derive(Clone, Debug, Default, Deserialize, Serialize)]
191#[serde(rename_all = "camelCase")]
192pub struct Page {
193    #[serde(rename = "type")]
194    #[serde(alias = "objectType")]
195    #[serde(alias = "verb")]
196    kind: PageType,
197
198    /// Adds all valid object properties to this struct
199    #[serde(flatten)]
200    pub object_props: ObjectProperties,
201}
202
203impl Object for Page {}
204impl ObjectExt for Page {
205    fn props(&self) -> &ObjectProperties {
206        &self.object_props
207    }
208
209    fn props_mut(&mut self) -> &mut ObjectProperties {
210        &mut self.object_props
211    }
212}
213
214/// Represents a logical or physical location.
215///
216/// The Place object is used to represent both physical and logical locations. While numerous
217/// existing vocabularies exist for describing locations in a variety of ways, inconsistencies and
218/// incompatibilities between those vocabularies make it difficult to achieve appropriate
219/// interoperability between implementations. The Place object is included within the Activity
220/// vocabulary to provide a minimal, interoperable starting point for describing locations
221/// consistently across Activity Streams 2.0 implementations.
222///
223/// The Place object is intentionally flexible. It can, for instance, be used to identify a location
224/// simply by name, or by longitude and latitude.
225///
226/// The Place object can also describe an area around a given point using the radius property, the
227/// altitude of the location, and a degree of accuracy.
228///
229/// While publishers are not required to use these specific properties and MAY make use of other
230/// mechanisms for describing locations, consuming implementations that support the Place object
231/// MUST support the use of these properties.
232#[derive(Clone, Debug, Default, Deserialize, Serialize)]
233#[serde(rename_all = "camelCase")]
234pub struct Place {
235    #[serde(rename = "type")]
236    #[serde(alias = "objectType")]
237    #[serde(alias = "verb")]
238    kind: PlaceType,
239
240    /// Adds all valid object properties to this struct
241    #[serde(flatten)]
242    pub object_props: ObjectProperties,
243
244    /// Adds all valid place properties to this struct
245    #[serde(flatten)]
246    pub place: PlaceProperties,
247}
248
249impl Object for Place {}
250impl ObjectExt for Place {
251    fn props(&self) -> &ObjectProperties {
252        &self.object_props
253    }
254
255    fn props_mut(&mut self) -> &mut ObjectProperties {
256        &mut self.object_props
257    }
258}
259
260/// A Profile is a content object that describes another `Object`, typically used to describe
261/// `Actor` Type objects.
262///
263/// The `describes` property is used to reference the object being described by the profile.
264#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
265#[serde(rename_all = "camelCase")]
266pub struct Profile {
267    #[serde(rename = "type")]
268    #[serde(alias = "objectType")]
269    #[serde(alias = "verb")]
270    kind: ProfileType,
271
272    /// Adds all valid object properties to this struct
273    #[serde(flatten)]
274    pub object_props: ObjectProperties,
275
276    /// Adds all valid profile properties to this struct
277    #[serde(flatten)]
278    pub profile: ProfileProperties,
279}
280
281impl Object for Profile {}
282impl ObjectExt for Profile {
283    fn props(&self) -> &ObjectProperties {
284        &self.object_props
285    }
286
287    fn props_mut(&mut self) -> &mut ObjectProperties {
288        &mut self.object_props
289    }
290}
291
292/// Describes a relationship between two individuals.
293///
294/// The subject and object properties are used to identify the connected individuals.
295///
296/// The `Relationship` object is used to represent relationships between individuals. It can be
297/// used, for instance, to describe that one person is a friend of another, or that one person is a
298/// member of a particular organization. The intent of modeling Relationship in this way is to allow
299/// descriptions of activities that operate on the relationships in general, and to allow
300/// representation of Collections of relationships.
301///
302/// For instance, many social systems have a notion of a "friends list". These are the collection of
303/// individuals that are directly connected within a person's social graph. Suppose we have a user,
304/// Sally, with direct relationships to users Joe and Jane. Sally follows Joe's updates while Sally
305/// and Jane have a mutual relationship.
306#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
307#[serde(rename_all = "camelCase")]
308pub struct Relationship {
309    #[serde(rename = "type")]
310    #[serde(alias = "objectType")]
311    #[serde(alias = "verb")]
312    kind: RelationshipType,
313
314    /// Adds all valid object properties to this struct
315    #[serde(flatten)]
316    pub object_props: ObjectProperties,
317
318    /// Adds all valid relationship properties to this struct
319    #[serde(flatten)]
320    pub relationship: RelationshipProperties,
321}
322
323impl Object for Relationship {}
324impl ObjectExt for Relationship {
325    fn props(&self) -> &ObjectProperties {
326        &self.object_props
327    }
328
329    fn props_mut(&mut self) -> &mut ObjectProperties {
330        &mut self.object_props
331    }
332}
333
334/// A Tombstone represents a content object that has been deleted.
335///
336/// It can be used in Collections to signify that there used to be an object at this position, but
337/// it has been deleted.
338#[derive(Clone, Debug, Default, Deserialize, Serialize)]
339#[serde(rename_all = "camelCase")]
340pub struct Tombstone {
341    #[serde(rename = "type")]
342    #[serde(alias = "objectType")]
343    #[serde(alias = "verb")]
344    kind: TombstoneType,
345
346    /// Adds all valid object properties to this struct
347    #[serde(flatten)]
348    pub object_props: ObjectProperties,
349
350    /// Adds all valid tombstone properties to this struct
351    #[serde(flatten)]
352    pub tombstone_props: TombstoneProperties,
353}
354
355impl Object for Tombstone {}
356impl ObjectExt for Tombstone {
357    fn props(&self) -> &ObjectProperties {
358        &self.object_props
359    }
360
361    fn props_mut(&mut self) -> &mut ObjectProperties {
362        &mut self.object_props
363    }
364}
365
366/// Represents a video document of any kind.
367#[derive(Clone, Debug, Default, Deserialize, Serialize)]
368#[serde(rename_all = "camelCase")]
369pub struct Video {
370    #[serde(rename = "type")]
371    #[serde(alias = "objectType")]
372    #[serde(alias = "verb")]
373    kind: VideoType,
374
375    /// Adds all valid object properties to this struct
376    #[serde(flatten)]
377    pub object_props: ObjectProperties,
378}
379
380impl Object for Video {}
381impl ObjectExt for Video {
382    fn props(&self) -> &ObjectProperties {
383        &self.object_props
384    }
385
386    fn props_mut(&mut self) -> &mut ObjectProperties {
387        &mut self.object_props
388    }
389}