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
61
62
63
64
65
#[macro_export]
macro_rules! findable {
($class_name:expr, $driver_name:expr, $port: ty, $debug_name:expr, $port_prefix:expr) => {
fn map_error(e: Ev3Error) -> Ev3Error {
match e {
e @ Ev3Error::InternalError { .. } => e,
Ev3Error::NotConnected { device: _, port } => Ev3Error::NotConnected {
device: $debug_name.to_owned(),
port,
},
Ev3Error::MultipleMatches { device: _, ports } => Ev3Error::MultipleMatches {
device: $debug_name.to_owned(),
ports: ports
.iter()
.map(|item| <$port>::format_name(item))
.collect(),
},
}
}
pub fn get(port: $port) -> Ev3Result<Self> {
let name = Driver::find_name_by_port_and_driver($class_name, &port, $driver_name)
.map_err(Self::map_error)?;
Ok(Self::new(Driver::new($class_name, &name)))
}
pub fn find() -> Ev3Result<Self> {
let name =
Driver::find_name_by_driver($class_name, $driver_name).map_err(Self::map_error)?;
Ok(Self::new(Driver::new($class_name, &name)))
}
pub fn list() -> Ev3Result<Vec<Self>> {
Ok(Driver::find_names_by_driver($class_name, $driver_name)?
.iter()
.map(|name| Self::new(Driver::new($class_name, &name)))
.collect())
}
};
}