eggbug/ask.rs
1use derive_more::{Display, From, FromStr, Into};
2use serde::{Deserialize, Serialize};
3
4/// An ask ID.
5#[derive(
6 Clone,
7 Debug,
8 Default,
9 Deserialize,
10 Display,
11 Eq,
12 From,
13 FromStr,
14 Hash,
15 Into,
16 Ord,
17 PartialEq,
18 PartialOrd,
19 Serialize,
20)]
21#[serde(transparent)]
22pub struct AskId(pub String);
23
24/// Describes the contents of an ask. Asks can't be created client-side, only decoded when reading
25/// content from the server.
26#[derive(Clone, Debug)]
27pub struct Ask {
28 pub(crate) ask_id: AskId,
29 /// Information about the account that sent this ask, if it wasn't sent anonymously.
30 pub asker: Option<Asker>,
31 /// Markdown content for the ask, displayed after the asker's name.
32 pub content: String,
33 /// The date and time this ask was sent.
34 pub sent_at: chrono::DateTime<chrono::Utc>,
35}
36
37impl Ask {
38 /// Get the ID of the ask represented by this struct.
39 #[must_use]
40 pub fn id(&self) -> &str {
41 &self.ask_id.0
42 }
43}
44
45/// Describes the project that sent an ask.
46#[derive(Clone, Debug)]
47pub struct Asker {
48 /// The unique handle of the asker.
49 pub handle: String,
50 /// The display name of the asker, which may be different from the handle.
51 pub display_name: String,
52}