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
use num_traits::FromPrimitive;
use crate::Error;
use crate::ember::Status;
crate::frame::parameters::handler!(
0x001C,
{ channel: u8, status: u8 },
impl {
impl Handler {
/// The channel on which the current error occurred.
///
/// Undefined for the case of [`Status::Success`].
#[must_use]
pub fn channel(&self) -> Option<u8> {
match self.status() {
Ok(()) => None,
Err(_) => Some(self.channel),
}
}
/// The error condition that occurred on the current channel.
///
/// Value will be [`Status::Success`] when the scan has completed.
///
/// # Errors
///
/// Returns an [`Error`] if the status is invalid.
pub fn status(&self) -> Result<(), Error> {
match Status::from_u8(self.status).ok_or(self.status) {
Ok(Status::Success) => Ok(()),
other => Err(other.into()),
}
}
}
impl TryFrom<Handler> for u8 {
type Error = Error;
fn try_from(handler: Handler) -> Result<Self, Self::Error> {
handler.status().map(|()| handler.channel)
}
}
}
);