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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use num_derive::{FromPrimitive, ToPrimitive};
use realsense_sys as sys;
use std::fmt::{Display, Formatter, Result};
#[repr(i32)]
#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Rs2Exception {
Unknown = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_UNKNOWN as i32,
CameraDisconnected = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_CAMERA_DISCONNECTED as i32,
Backend = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_BACKEND as i32,
InvalidValue = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_INVALID_VALUE as i32,
WrongApiCallSequence =
sys::rs2_exception_type_RS2_EXCEPTION_TYPE_WRONG_API_CALL_SEQUENCE as i32,
NotImplemented = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_NOT_IMPLEMENTED as i32,
DeviceInRecoveryMode =
sys::rs2_exception_type_RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE as i32,
IoDeviceFailure = sys::rs2_exception_type_RS2_EXCEPTION_TYPE_IO as i32,
}
impl Display for Rs2Exception {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let s = match self {
Rs2Exception::Unknown => "Unknown",
Rs2Exception::CameraDisconnected => "CameraDisconnected",
Rs2Exception::Backend => "Backend",
Rs2Exception::InvalidValue => "InvalidValue",
Rs2Exception::WrongApiCallSequence => "WrongAPICallSequence",
Rs2Exception::NotImplemented => "NotImplemented",
Rs2Exception::DeviceInRecoveryMode => "DeviceInRecoveryMode",
Rs2Exception::IoDeviceFailure => "IODeviceFailure",
};
write!(f, "{}", s)
}
}
#[cfg(test)]
mod tests {
use super::*;
use num_traits::FromPrimitive;
#[test]
fn all_variants_exist() {
for i in 0..sys::rs2_exception_type_RS2_EXCEPTION_TYPE_COUNT as i32 {
assert!(
Rs2Exception::from_i32(i).is_some(),
"Rs2Exception variant for ordinal {} does not exist.",
i,
);
}
}
}