openleadr_client/
target.rs

1use openleadr_wire::target::TargetType;
2
3/// Target for a query to the VTN
4#[derive(Copy, Clone, Debug)]
5pub enum Target<'a> {
6    /// Target by a specific program name
7    Program(&'a str),
8
9    /// Target by a list of program names
10    Programs(&'a [&'a str]),
11
12    /// Target by a specific event name
13    Event(&'a str),
14
15    /// Target by a list of event names
16    Events(&'a [&'a str]),
17
18    /// Target by a specific VEN name
19    VEN(&'a str),
20
21    /// Target by a list of VEN names
22    VENs(&'a [&'a str]),
23
24    /// Target by a specific group name
25    Group(&'a str),
26
27    /// Target by a list of group names
28    Groups(&'a [&'a str]),
29
30    /// Target by a specific resource name
31    Resource(&'a str),
32
33    /// Target by a list of resource names
34    Resources(&'a [&'a str]),
35
36    /// Target by a specific service area
37    ServiceArea(&'a str),
38
39    /// Target by a list of service areas
40    ServiceAreas(&'a [&'a str]),
41
42    /// Target by a specific power service location
43    PowerServiceLocation(&'a str),
44
45    /// Target by a list of power service locations
46    PowerServiceLocations(&'a [&'a str]),
47
48    /// Target using some other kind of privately defined target type, using a single target value
49    Other(&'a str, &'a str),
50
51    /// Target using some other kind of privately defined target type, with a list of values
52    Others(&'a str, &'a [&'a str]),
53}
54
55impl Target<'_> {
56    /// Get the target label for this specific target
57    pub fn target_label(&self) -> TargetType {
58        match self {
59            Target::Program(_) | Target::Programs(_) => TargetType::ProgramName,
60            Target::Event(_) | Target::Events(_) => TargetType::EventName,
61            Target::VEN(_) | Target::VENs(_) => TargetType::VENName,
62            Target::Group(_) | Target::Groups(_) => TargetType::Group,
63            Target::Resource(_) | Target::Resources(_) => TargetType::ResourceName,
64            Target::ServiceArea(_) | Target::ServiceAreas(_) => TargetType::ServiceArea,
65            Target::PowerServiceLocation(_) | Target::PowerServiceLocations(_) => {
66                TargetType::PowerServiceLocation
67            }
68            Target::Other(p, _) | Target::Others(p, _) => TargetType::Private(p.to_string()),
69        }
70    }
71
72    /// Get the list of target values for this specific target
73    pub fn target_values(&self) -> &[&str] {
74        match self {
75            Target::Program(v) => std::slice::from_ref(v),
76            Target::Programs(v) => v,
77            Target::Event(v) => std::slice::from_ref(v),
78            Target::Events(v) => v,
79            Target::VEN(v) => std::slice::from_ref(v),
80            Target::VENs(v) => v,
81            Target::Group(v) => std::slice::from_ref(v),
82            Target::Groups(v) => v,
83            Target::Resource(v) => std::slice::from_ref(v),
84            Target::Resources(v) => v,
85            Target::ServiceArea(v) => std::slice::from_ref(v),
86            Target::ServiceAreas(v) => v,
87            Target::PowerServiceLocation(v) => std::slice::from_ref(v),
88            Target::PowerServiceLocations(v) => v,
89            Target::Other(_, v) => std::slice::from_ref(v),
90            Target::Others(_, v) => v,
91        }
92    }
93}