Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
fn accept_writer<B: UsbBus>(
xfer: ControlIn<B>,
f: impl FnOnce(&mut DescriptorWriter) -> Result<()>,
) {
) -> Result<()> {
xfer.accept(|buf| {
let mut writer = DescriptorWriter::new(buf);
f(&mut writer)?;
Ok(writer.position())
})
.ok();
}

match dtype {
Expand Down Expand Up @@ -513,17 +512,16 @@ impl<B: UsbBus> UsbDevice<'_, B> {
};

if let Some(s) = s {
accept_writer(xfer, |w| w.string(s));
accept_writer(xfer, |w| w.string(s))
} else {
xfer.reject().ok();
xfer.reject()
}
}
}

_ => {
xfer.reject().ok();
}
_ => xfer.reject(),
}
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think unwrap()ing the result here is the best approach. This will inject fmt bloat into applications for people that may not be able to pay the memory overhead.

We should likely bubble the error up instead and let the user handle the Result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

fn reset(&mut self, classes: &mut ClassList<'_, B>) {
Expand Down