1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Durable Wave registry identity and placement.
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use crate::id::WaveId;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Wave {
pub id: WaveId,
pub name: String,
/// The single repo this wave targets. A wave = exactly one repo.
pub repo: String,
#[serde(with = "time::serde::rfc3339::option")]
pub created_at: Option<OffsetDateTime>,
/// Parent wave in the chord tree. `None` for a root wave. A chord is simply
/// a wave that has children (`children_of(id)` non-empty) — there is no
/// `wave_type` discriminator.
pub parent_wave_id: Option<WaveId>,
}
impl Wave {
pub fn new(id: WaveId, name: String, repo: String) -> Self {
Self {
id,
name,
repo,
created_at: Some(OffsetDateTime::now_utc()),
parent_wave_id: None,
}
}
/// Attach this wave to a parent, making it a child in the chord tree.
pub fn with_parent(mut self, parent: WaveId) -> Self {
self.parent_wave_id = Some(parent);
self
}
pub fn id(&self) -> &WaveId {
&self.id
}
/// Parent wave in the chord tree, `None` for a root wave.
pub fn parent_wave_id(&self) -> Option<&WaveId> {
self.parent_wave_id.as_ref()
}
pub fn name(&self) -> &str {
&self.name
}
/// The repo this wave targets.
pub fn repo(&self) -> &str {
&self.repo
}
pub fn created_at(&self) -> Option<OffsetDateTime> {
self.created_at
}
}