mammut/
status_builder.rs

1/// A builder pattern struct for constructing a status.
2#[derive(Debug, Default, Clone, Serialize)]
3pub struct StatusBuilder {
4    /// The text of the status.
5    pub status: String,
6    /// The ID of the status this status is replying to, if the status is
7    /// a reply.
8    #[serde(skip_serializing_if="Option::is_none")]
9    pub in_reply_to_id: Option<String>,
10    /// Ids of media attachments being attached to the status.
11    #[serde(skip_serializing_if="Option::is_none")]
12    pub media_ids: Option<Vec<String>>,
13    /// Whether current status is sensitive.
14    #[serde(skip_serializing_if="Option::is_none")]
15    pub sensitive: Option<bool>,
16    /// Text to precede the normal status text.
17    #[serde(skip_serializing_if="Option::is_none")]
18    pub spoiler_text: Option<String>,
19    /// Visibility of the status, defaults to `Public`.
20    #[serde(skip_serializing_if="Option::is_none")]
21    pub visibility: Option<Visibility>,
22}
23
24/// The visibility of a status.
25#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
26pub enum Visibility {
27    /// A Direct message to a user
28    #[serde(rename = "direct")]
29    Direct,
30    /// Only available to followers
31    #[serde(rename = "private")]
32    Private,
33    /// Not shown in public timelines
34    #[serde(rename = "unlisted")]
35    Unlisted,
36    /// Posted to public timelines
37    #[serde(rename = "public")]
38    Public,
39}
40
41impl StatusBuilder {
42
43    /// Create a new status with text.
44    /// ```
45    /// use mammut::status_builder::StatusBuilder;
46    ///
47    /// let status = StatusBuilder::new("Hello World!".into());
48    /// ```
49    pub fn new(status: String) -> Self {
50        StatusBuilder {
51            status: status,
52            ..Self::default()
53        }
54    }
55}
56
57impl Default for Visibility {
58    fn default() -> Self {
59        Visibility::Public
60    }
61}