@@ -24,35 +24,51 @@ pub enum Type {
24
24
U16 = 0x0101 ,
25
25
U32 = 0x0102 ,
26
26
Area = 0x0106 ,
27
- }
28
27
29
- impl TryFrom < u32 > for Type {
30
- type Error = ( ) ;
28
+ Unknown ( u32 ) ,
29
+ }
31
30
32
- fn try_from ( repr : u32 ) -> Result < Self , Self :: Error > {
31
+ impl From < u32 > for Type {
32
+ fn from ( repr : u32 ) -> Self {
33
33
match repr {
34
- 1 => Ok ( Type :: Integer ) ,
35
- 2 => Ok ( Type :: Boolean ) ,
36
- 3 => Ok ( Type :: Menu ) ,
37
- 4 => Ok ( Type :: Button ) ,
38
- 5 => Ok ( Type :: Integer64 ) ,
39
- 6 => Ok ( Type :: CtrlClass ) ,
40
- 7 => Ok ( Type :: String ) ,
41
- 8 => Ok ( Type :: Bitmask ) ,
42
- 9 => Ok ( Type :: IntegerMenu ) ,
43
-
44
- 0x0100 => Ok ( Type :: U8 ) ,
45
- 0x0101 => Ok ( Type :: U16 ) ,
46
- 0x0102 => Ok ( Type :: U32 ) ,
47
- 0x0106 => Ok ( Type :: Area ) ,
48
- _ => Err ( ( ) ) ,
34
+ 1 => Self :: Integer ,
35
+ 2 => Self :: Boolean ,
36
+ 3 => Self :: Menu ,
37
+ 4 => Self :: Button ,
38
+ 5 => Self :: Integer64 ,
39
+ 6 => Self :: CtrlClass ,
40
+ 7 => Self :: String ,
41
+ 8 => Self :: Bitmask ,
42
+ 9 => Self :: IntegerMenu ,
43
+
44
+ 0x0100 => Self :: U8 ,
45
+ 0x0101 => Self :: U16 ,
46
+ 0x0102 => Self :: U32 ,
47
+ 0x0106 => Self :: Area ,
48
+ repr => Self :: Unknown ( repr ) ,
49
49
}
50
50
}
51
51
}
52
52
53
53
impl From < Type > for u32 {
54
54
fn from ( t : Type ) -> Self {
55
- t as Self
55
+ match t {
56
+ Type :: Integer => 1 ,
57
+ Type :: Boolean => 2 ,
58
+ Type :: Menu => 3 ,
59
+ Type :: Button => 4 ,
60
+ Type :: Integer64 => 5 ,
61
+ Type :: CtrlClass => 6 ,
62
+ Type :: String => 7 ,
63
+ Type :: Bitmask => 8 ,
64
+ Type :: IntegerMenu => 9 ,
65
+
66
+ Type :: U8 => 0x0100 ,
67
+ Type :: U16 => 0x0101 ,
68
+ Type :: U32 => 0x0102 ,
69
+ Type :: Area => 0x0106 ,
70
+ Type :: Unknown ( t) => t,
71
+ }
56
72
}
57
73
}
58
74
@@ -168,7 +184,7 @@ impl From<v4l2_query_ext_ctrl> for Description {
168
184
fn from ( ctrl : v4l2_query_ext_ctrl ) -> Self {
169
185
Self {
170
186
id : ctrl. id ,
171
- typ : Type :: try_from ( ctrl. type_ ) . unwrap ( ) ,
187
+ typ : Type :: from ( ctrl. type_ ) ,
172
188
name : unsafe { ffi:: CStr :: from_ptr ( ctrl. name . as_ptr ( ) ) }
173
189
. to_str ( )
174
190
. unwrap ( )
0 commit comments