pzzld_server/workers/
config.rs1use crate::types::Uid;
6
7#[derive(
8 Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
9)]
10pub struct WorkerConfig {
11 #[serde(default = "rand::random")]
12 pub id: Uid,
13 #[serde(default)]
14 pub(crate) name: String,
15}
16
17impl WorkerConfig {
18 pub fn new() -> Self {
19 Self {
20 id: rand::random(),
21 name: String::new(),
22 }
23 }
24
25 pub fn id(&self) -> Uid {
26 self.id
27 }
28
29 pub fn name(&self) -> &str {
30 &self.name
31 }
32
33 pub fn set_name(&mut self, name: impl ToString) {
34 self.name = name.to_string();
35 }
36
37 pub fn with_id(self, id: Uid) -> Self {
38 Self { id, ..self }
39 }
40
41 pub fn with_name(self, name: impl ToString) -> Self {
42 Self {
43 name: name.to_string(),
44 ..self
45 }
46 }
47}
48
49impl Default for WorkerConfig {
50 fn default() -> Self {
51 Self::new()
52 }
53}