Skip to main content

collect_settings/
project.rs

1use serde::{Deserialize, Serialize};
2
3/// Name, icon and colour of the project as shown in the app's project switcher.
4#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
5pub struct Project {
6    /// Project name (shown on the main screen).
7    #[serde(default, skip_serializing_if = "Option::is_none")]
8    pub name: Option<String>,
9    /// A single character drawn in the project badge.
10    #[serde(default, skip_serializing_if = "Option::is_none")]
11    pub icon: Option<String>,
12    /// Badge colour as `#rrggbb`.
13    #[serde(default, skip_serializing_if = "Option::is_none")]
14    pub color: Option<String>,
15}
16
17impl Project {
18    /// A project with the given name and no icon or colour.
19    pub fn new(name: impl Into<String>) -> Self {
20        Project {
21            name: Some(name.into()),
22            ..Default::default()
23        }
24    }
25
26    /// Set the badge character.
27    pub fn icon(mut self, icon: char) -> Self {
28        self.icon = Some(icon.to_string());
29        self
30    }
31
32    /// Set the badge colour (`#rrggbb`).
33    pub fn color(mut self, color: impl Into<String>) -> Self {
34        self.color = Some(color.into());
35        self
36    }
37}