Skip to content

Commit d208098

Browse files
committed
chore: Less deep indentation
1 parent 9c49338 commit d208098

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

backend/src/daemon/server.rs

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,55 +52,51 @@ impl<R: Read, W: Write> DaemonServer<R, W> {
5252
}
5353

5454
//TODO: should we continue through HID errors?
55-
match HidApi::new() {
56-
Ok(api) => {
57-
for info in api.device_list() {
58-
match (info.vendor_id(), info.product_id()) {
59-
// System76 launch_1
60-
(0x3384, 0x0001) => match info.interface_number() {
61-
//TODO: better way to determine this
62-
1 => match info.open_device(&api) {
63-
Ok(device) => match AccessHid::new(device, 10, 100) {
64-
Ok(access) => match unsafe { Ec::new(access) } {
65-
Ok(ec) => {
66-
info!("Adding USB HID EC at {:?}", info.path());
67-
let id = BoardId(Uuid::new_v4().as_u128());
68-
boards.insert(id, ec.into_dyn());
69-
board_ids.push(id);
70-
}
71-
Err(err) => {
72-
error!(
73-
"Failed to probe USB HID EC at {:?}: {:?}",
74-
info.path(),
75-
err
76-
);
77-
}
78-
},
79-
Err(err) => {
80-
error!(
81-
"Failed to access USB HID EC at {:?}: {:?}",
82-
info.path(),
83-
err
84-
);
85-
}
86-
},
55+
let hidapi = match HidApi::new() {
56+
Ok(api) => Some(api),
57+
Err(err) => {
58+
error!("Failed to list USB HID ECs: {:?}", err);
59+
None
60+
}
61+
};
62+
63+
if let Some(api) = &hidapi {
64+
for info in api.device_list() {
65+
match (info.vendor_id(), info.product_id(), info.interface_number()) {
66+
// System76 launch_1
67+
//TODO: better way to determine this
68+
(0x3384, 0x0001, 1) => match info.open_device(&api) {
69+
Ok(device) => match AccessHid::new(device, 10, 100) {
70+
Ok(access) => match unsafe { Ec::new(access) } {
71+
Ok(ec) => {
72+
info!("Adding USB HID EC at {:?}", info.path());
73+
let id = BoardId(Uuid::new_v4().as_u128());
74+
boards.insert(id, ec.into_dyn());
75+
board_ids.push(id);
76+
}
8777
Err(err) => {
8878
error!(
89-
"Failed to open USB HID EC at {:?}: {:?}",
79+
"Failed to probe USB HID EC at {:?}: {:?}",
9080
info.path(),
9181
err
9282
);
9383
}
9484
},
95-
_ => (),
85+
Err(err) => {
86+
error!(
87+
"Failed to access USB HID EC at {:?}: {:?}",
88+
info.path(),
89+
err
90+
);
91+
}
9692
},
97-
_ => (),
98-
}
93+
Err(err) => {
94+
error!("Failed to open USB HID EC at {:?}: {:?}", info.path(), err);
95+
}
96+
},
97+
_ => (),
9998
}
10099
}
101-
Err(err) => {
102-
error!("Failed to list USB HID ECs: {:?}", err);
103-
}
104100
}
105101

106102
Ok(Self {

0 commit comments

Comments
 (0)