polyphony_types/entities/
attachment.rs

1use serde::{Deserialize, Serialize};
2
3use crate::utils::Snowflake;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct Attachment {
7    pub id: Snowflake,
8    pub filename: String,
9    pub description: Option<String>,
10    pub content_type: Option<String>,
11    pub size: u64,
12    pub url: String,
13    pub proxy_url: String,
14    pub height: Option<u64>,
15    pub width: Option<u64>,
16    pub message_id: Snowflake,
17    pub ephemeral: Option<bool>,
18    pub duration_secs: Option<f32>,
19    pub waveform: Option<String>,
20    #[serde(skip_serializing)]
21    pub content: Vec<u8>,
22}
23
24#[derive(Debug, Serialize, Deserialize, Clone)]
25
26pub struct PartialDiscordFileAttachment {
27    pub id: Option<i16>,
28    pub filename: String,
29    pub description: Option<String>,
30    pub content_type: Option<String>,
31    pub size: Option<i64>,
32    pub url: Option<String>,
33    pub proxy_url: Option<String>,
34    pub height: Option<i32>,
35    pub width: Option<i32>,
36    pub ephemeral: Option<bool>,
37    pub duration_secs: Option<f32>,
38    pub waveform: Option<String>,
39    #[serde(skip_serializing)]
40    pub content: Vec<u8>,
41}
42
43impl PartialDiscordFileAttachment {
44    /**
45    Moves `self.content` out of `self` and returns it.
46    # Returns
47    Vec<u8>
48     */
49    pub fn move_content(self) -> (Vec<u8>, PartialDiscordFileAttachment) {
50        let content = self.content;
51        let updated_struct = PartialDiscordFileAttachment {
52            id: self.id,
53            filename: self.filename,
54            description: self.description,
55            content_type: self.content_type,
56            size: self.size,
57            url: self.url,
58            proxy_url: self.proxy_url,
59            height: self.height,
60            width: self.width,
61            ephemeral: self.ephemeral,
62            duration_secs: self.duration_secs,
63            waveform: self.waveform,
64            content: Vec::new(),
65        };
66        (content, updated_struct)
67    }
68
69    pub fn move_filename(self) -> (String, PartialDiscordFileAttachment) {
70        let filename = self.filename;
71        let updated_struct = PartialDiscordFileAttachment {
72            id: self.id,
73            filename: String::new(),
74            description: self.description,
75            content_type: self.content_type,
76            size: self.size,
77            url: self.url,
78            proxy_url: self.proxy_url,
79            height: self.height,
80            width: self.width,
81
82            ephemeral: self.ephemeral,
83            duration_secs: self.duration_secs,
84            waveform: self.waveform,
85            content: self.content,
86        };
87        (filename, updated_struct)
88    }
89
90    pub fn move_content_type(self) -> (Option<String>, PartialDiscordFileAttachment) {
91        let content_type = self.content_type;
92        let updated_struct = PartialDiscordFileAttachment {
93            id: self.id,
94            filename: self.filename,
95            description: self.description,
96            content_type: None,
97            size: self.size,
98            url: self.url,
99            proxy_url: self.proxy_url,
100            height: self.height,
101            width: self.width,
102            ephemeral: self.ephemeral,
103            duration_secs: self.duration_secs,
104            waveform: self.waveform,
105            content: self.content,
106        };
107        (content_type, updated_struct)
108    }
109
110    pub fn set_id(&mut self, id: i16) {
111        self.id = Some(id);
112    }
113}