detritus_protocol/
source.rs1use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct SourceId {
9 pub project: String,
11 pub platform: String,
13 pub version: String,
15 pub install_id: Uuid,
17}
18
19impl SourceId {
20 #[must_use]
24 pub fn canonical(&self) -> String {
25 format!(
26 "{}/{}/{}/{}",
27 self.project, self.platform, self.version, self.install_id
28 )
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 #[cfg_attr(coverage_nightly, coverage(off))]
38 fn canonical_joins_fields_with_slashes() {
39 let source = SourceId {
42 project: "detritus".to_owned(),
43 platform: "linux".to_owned(),
44 version: "1.2.3".to_owned(),
45 install_id: Uuid::nil(),
46 };
47 assert_eq!(
48 source.canonical(),
49 "detritus/linux/1.2.3/00000000-0000-0000-0000-000000000000"
50 );
51 }
52}