Skip to content

Commit

Permalink
Make port_chain return Vec not Option<Vec>
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmehall committed Aug 10, 2024
1 parent 0b51e76 commit 5afbb29
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct DeviceInfo {

pub(crate) bus_id: String,
pub(crate) device_address: u8,
pub(crate) port_chain: Option<Vec<u8>>,
pub(crate) port_chain: Vec<u8>,

pub(crate) vendor_id: u16,
pub(crate) product_id: u16,
Expand Down Expand Up @@ -141,8 +141,8 @@ impl DeviceInfo {
///
/// Since USB SuperSpeed is a separate topology from USB 2.0 speeds, a
/// physical port may be identified differently depending on speed.
pub fn port_chain(&self) -> Option<&[u8]> {
self.port_chain.as_deref()
pub fn port_chain(&self) -> &[u8] {
&self.port_chain
}

/// *(Windows-only)* Driver associated with the device as a whole
Expand Down
3 changes: 2 additions & 1 deletion src/platform/linux_usbfs/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ pub fn probe_device(path: SysfsPath) -> Result<DeviceInfo, SysfsError> {
p.split('.')
.map(|v| v.parse::<u8>().ok())
.collect::<Option<Vec<u8>>>()
});
}).unwrap_or_default();

Ok(DeviceInfo {
busnum,
bus_id: format!("{busnum:03}"),
Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos_iokit/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn probe_device(device: IoService) -> Option<DeviceInfo> {
location_id,
bus_id: format!("{:02x}", (location_id >> 24) as u8),
device_address: get_integer_property(&device, "USB Address")? as u8,
port_chain: Some(parse_location_id(location_id)),
port_chain: parse_location_id(location_id),
vendor_id: get_integer_property(&device, "idVendor")? as u16,
product_id: get_integer_property(&device, "idProduct")? as u16,
device_version: get_integer_property(&device, "bcdDevice")? as u16,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows_winusb/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn probe_device(devinst: DevInst) -> Option<DeviceInfo> {
parent_instance_id,
devinst,
port_number,
port_chain: Some(port_chain),
port_chain,
driver: Some(driver).filter(|s| !s.is_empty()),
bus_id,
device_address: info.address,
Expand Down

0 comments on commit 5afbb29

Please sign in to comment.