activitystreams_types/activity/
question.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
20use activitystreams_derive::Properties;
21use activitystreams_traits::{Activity, IntransitiveActivity, Object};
22use serde_derive::{Deserialize, Serialize};
23
24use super::{
25    kind::QuestionType,
26    properties::{ActivityProperties, QuestionProperties},
27    ActivityExt,
28};
29use crate::object::{properties::ObjectProperties, ObjectExt};
30
31/// Represents a question being asked.
32///
33/// Question objects are an extension of IntransitiveActivity. That is, the Question object is an
34/// Activity, but the direct object is the question itself and therefore it would not contain an
35/// object property.
36///
37/// Either of the anyOf and oneOf properties MAY be used to express possible answers, but a
38/// Question object MUST NOT have both properties.
39#[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)]
40#[serde(rename_all = "camelCase")]
41pub struct Question {
42    #[serde(rename = "type")]
43    #[serde(alias = "objectType")]
44    #[serde(alias = "verb")]
45    pub kind: QuestionType,
46
47    /// Adds all valid question properties to this struct
48    #[serde(flatten)]
49    pub question_props: QuestionProperties,
50
51    /// Adds all valid object properties to this struct
52    #[serde(flatten)]
53    pub object_props: ObjectProperties,
54
55    /// Adds all valid activity properties to this struct
56    #[serde(flatten)]
57    pub activity_props: ActivityProperties,
58}
59
60impl Object for Question {}
61impl ObjectExt for Question {
62    fn props(&self) -> &ObjectProperties {
63        &self.object_props
64    }
65
66    fn props_mut(&mut self) -> &mut ObjectProperties {
67        &mut self.object_props
68    }
69}
70impl Activity for Question {}
71impl ActivityExt for Question {
72    fn props(&self) -> &ActivityProperties {
73        &self.activity_props
74    }
75
76    fn props_mut(&mut self) -> &mut ActivityProperties {
77        &mut self.activity_props
78    }
79}
80impl IntransitiveActivity for Question {}