Skip to content

Commit 10b4e12

Browse files
authored
Merge pull request #87 from eldruin/small-simplifications
Small code simplifications
2 parents d1321ae + c99cf6e commit 10b4e12

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/control_pipe.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
122122
return Some(req);
123123
}
124124

125-
return None;
125+
None
126126
}
127127

128128
pub fn handle_out<'p>(&'p mut self) -> Option<Request> {
@@ -160,7 +160,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
160160
}
161161
}
162162

163-
return None;
163+
None
164164
}
165165

166166
pub fn handle_in_complete(&mut self) -> bool {
@@ -191,7 +191,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
191191
}
192192
};
193193

194-
return false;
194+
false
195195
}
196196

197197
fn write_in_chunk(&mut self) {

src/descriptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub struct BosWriter<'w, 'a: 'w> {
372372
impl<'w, 'a: 'w> BosWriter<'w, 'a> {
373373
pub(crate) fn new(writer: &'w mut DescriptorWriter<'a>) -> Self {
374374
Self {
375-
writer: writer,
375+
writer,
376376
num_caps_mark: None,
377377
}
378378
}

src/device.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
193193
if (ep_in_complete & 1) != 0 {
194194
let completed = self.control.handle_in_complete();
195195

196-
if !B::QUIRK_SET_ADDRESS_BEFORE_STATUS {
197-
if completed && self.pending_address != 0 {
198-
self.bus.set_device_address(self.pending_address);
199-
self.pending_address = 0;
196+
if !B::QUIRK_SET_ADDRESS_BEFORE_STATUS
197+
&& completed
198+
&& self.pending_address != 0
199+
{
200+
self.bus.set_device_address(self.pending_address);
201+
self.pending_address = 0;
200202

201-
self.device_state = UsbDeviceState::Addressed;
202-
}
203+
self.device_state = UsbDeviceState::Addressed;
203204
}
204205
}
205206

@@ -275,7 +276,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
275276
}
276277
}
277278

278-
return false;
279+
false
279280
}
280281

281282
fn control_in(&mut self, classes: &mut ClassList<'_, B>, req: control::Request) {
@@ -508,7 +509,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
508509
classes
509510
.iter()
510511
.filter_map(|cls| cls.get_string(index, lang_id))
511-
.nth(0)
512+
.next()
512513
}
513514
};
514515

src/endpoint.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::bus::UsbBus;
22
use crate::{Result, UsbDirection};
33
use core::marker::PhantomData;
4-
use core::ptr;
54
use core::sync::atomic::{AtomicPtr, Ordering};
65

76
/// Trait for endpoint type markers.
@@ -77,7 +76,7 @@ impl<B: UsbBus, D: EndpointDirection> Endpoint<'_, B, D> {
7776

7877
fn bus(&self) -> &B {
7978
let bus_ptr = self.bus_ptr.load(Ordering::SeqCst);
80-
if bus_ptr == ptr::null_mut() {
79+
if bus_ptr.is_null() {
8180
panic!("UsbBus initialization not complete");
8281
}
8382

src/test_class.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ pub struct TestClass<'a, B: UsbBus> {
4646

4747
pub const VID: u16 = 0x16c0;
4848
pub const PID: u16 = 0x05dc;
49-
pub const MANUFACTURER: &'static str = "TestClass Manufacturer";
50-
pub const PRODUCT: &'static str = "virkkunen.net usb-device TestClass";
51-
pub const SERIAL_NUMBER: &'static str = "TestClass Serial";
52-
pub const CUSTOM_STRING: &'static str = "TestClass Custom String";
53-
pub const INTERFACE_STRING: &'static str = "TestClass Interface";
49+
pub const MANUFACTURER: &str = "TestClass Manufacturer";
50+
pub const PRODUCT: &str = "virkkunen.net usb-device TestClass";
51+
pub const SERIAL_NUMBER: &str = "TestClass Serial";
52+
pub const CUSTOM_STRING: &str = "TestClass Custom String";
53+
pub const INTERFACE_STRING: &str = "TestClass Interface";
5454

5555
pub const REQ_STORE_REQUEST: u8 = 1;
5656
pub const REQ_READ_BUFFER: u8 = 2;
@@ -59,7 +59,7 @@ pub const REQ_SET_BENCH_ENABLED: u8 = 4;
5959
pub const REQ_READ_LONG_DATA: u8 = 5;
6060
pub const REQ_UNKNOWN: u8 = 42;
6161

62-
pub const LONG_DATA: &'static [u8] = &[0x17; 257];
62+
pub const LONG_DATA: &[u8] = &[0x17; 257];
6363

6464
impl<B: UsbBus> TestClass<'_, B> {
6565
/// Creates a new TestClass.
@@ -105,7 +105,7 @@ impl<B: UsbBus> TestClass<'_, B> {
105105
&'a self,
106106
usb_bus: &'b UsbBusAllocator<B>,
107107
) -> UsbDeviceBuilder<'b, B> {
108-
UsbDeviceBuilder::new(&usb_bus, UsbVidPid(VID, PID))
108+
UsbDeviceBuilder::new(usb_bus, UsbVidPid(VID, PID))
109109
.manufacturer(MANUFACTURER)
110110
.product(PRODUCT)
111111
.serial_number(SERIAL_NUMBER)

0 commit comments

Comments
 (0)