rillrate_protocol/live_data/
auto_path.rs1use rill_protocol::io::provider::{EntryId, Path};
2
3pub struct AutoPath {
5 pub package: EntryId,
6 pub dashboard: EntryId,
7 pub group: EntryId,
8 pub name: EntryId,
9}
10
11impl AutoPath {
12 fn unassigned(name: EntryId) -> Self {
13 let entry = EntryId::from("unassigned");
14 Self {
15 package: entry.clone(),
16 dashboard: entry.clone(),
17 group: entry,
18 name,
19 }
20 }
21}
22
23impl From<AutoPath> for Path {
24 fn from(this: AutoPath) -> Self {
25 vec![this.package, this.dashboard, this.group, this.name].into()
26 }
27}
28
29impl From<[&str; 4]> for AutoPath {
30 fn from(array: [&str; 4]) -> Self {
31 Self {
32 package: array[0].into(),
33 dashboard: array[1].into(),
34 group: array[2].into(),
35 name: array[3].into(),
36 }
37 }
38}
39
40impl From<String> for AutoPath {
41 fn from(s: String) -> Self {
42 let s: &str = s.as_ref();
43 Self::from(s)
44 }
45}
46
47impl From<&str> for AutoPath {
48 fn from(s: &str) -> Self {
49 let path = s.parse::<Path>().map(Vec::from);
50 match path {
51 Ok(path) if path.len() == 4 => {
52 let mut items = path.into_iter();
53 Self {
54 package: items.next().unwrap(),
55 dashboard: items.next().unwrap(),
56 group: items.next().unwrap(),
57 name: items.next().unwrap(),
58 }
59 }
60 _ => Self::unassigned(EntryId::from(s)),
61 }
62 }
63}