Use bus_id() instead of busnum() when constructing/matching on DeviceArg - #60
Open
dingari wants to merge 3 commits into
Open
Use bus_id() instead of busnum() when constructing/matching on DeviceArg#60dingari wants to merge 3 commits into
bus_id() instead of busnum() when constructing/matching on DeviceArg#60dingari wants to merge 3 commits into
Conversation
…ching on DeviceArg busnum() is only available on Linux. The cross-platform equivalent is bus_id(). * Linux: String version of the busnum (e.g. \"001\") * MacOS: Top byte of the location ID (e.g. \"01\") * Windows: Unsure In any case, it should be consistent with the output of the `list` command in the example
sjoerdsimons
requested changes
Jun 16, 2026
sjoerdsimons
left a comment
Collaborator
There was a problem hiding this comment.
Changes seems fine; If you could fix the libusb example so CI succeeds then this should be ready to merge
dingari
force-pushed
the
device-arg-bus-id
branch
from
June 16, 2026 22:21
f053ba1 to
3db3a72
Compare
dingari
commented
Jun 16, 2026
| .iter() | ||
| .find(|d| match d { | ||
| Ok(device) => { | ||
| device.bus_number() == dev.bus_number && device.address() == dev.address |
Contributor
Author
There was a problem hiding this comment.
Don't know which is better...
let bus_number = dev.bus_id.parse().unwrap();
device.bus_number() == bus_number && device.address() == dev.address
or
let bus_id = format!("{:03}", device.bus_number());
bus_id == dev.bus_id && device.address() == dev.address
There was a problem hiding this comment.
Pull request overview
This PR updates the examples’ device listing/selection logic to use bus_id() (a cross-platform identifier) instead of Linux-only busnum()/numeric bus numbers, aligning device selection with the output of the list command.
Changes:
- Update
rockusb(nusb) example to print and match devices usingbus_id(). - Update
rockusb-libusbexample to match against the newDeviceArg.bus_id. - Change CLI
DeviceArgparsing frombus_number: u8tobus_id: String.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| rockusb/examples/rockusb.rs | Switches list output and device matching to bus_id() and prints VID/PID as hex. |
| rockusb/examples/rockusb-libusb.rs | Updates device matching to compare against the new string-based bus_id. |
| rockusb/examples/common.rs | Changes DeviceArg to store bus_id: String and updates parsing accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
35
to
37
| devices | ||
| .find(|d| d.busnum() == dev.bus_number && d.device_address() == dev.address) | ||
| .find(|d| d.bus_id() == dev.bus_id && d.device_address() == dev.address) | ||
| .ok_or_else(|| anyhow!("Specified device not found"))? |
Comment on lines
555
to
562
| let mut parts = device.split(':'); | ||
| let bus_number = parts | ||
| let bus_id = parts | ||
| .next() | ||
| .ok_or_else(|| anyhow!("No bus number: use <bus>:<address>"))? | ||
| .parse() | ||
| .map_err(|_| anyhow!("Bus should be a number"))?; | ||
| .ok_or_else(|| anyhow!("No bus id: use <bus>:<address>"))? | ||
| .to_string(); | ||
| let address = parts | ||
| .next() | ||
| .ok_or_else(|| anyhow!("No address: use <bus>:<address>"))? |
Comment on lines
32
to
43
| devices | ||
| .iter() | ||
| .find(|d| match d { | ||
| Ok(device) => { | ||
| device.bus_number() == dev.bus_number && device.address() == dev.address | ||
| let bus_id = format!("{:03}", device.bus_number()); | ||
| bus_id == dev.bus_id && device.address() == dev.address | ||
| } | ||
| Err(DeviceUnavalable { device, .. }) => { | ||
| device.bus_number() == dev.bus_number && device.address() == dev.address | ||
| let bus_id = format!("{:03}", device.bus_number()); | ||
| bus_id == dev.bus_id && device.address() == dev.address | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
busnum()is only available on Linux. The cross-platform equivalent isbus_id().In any case, it should be consistent with the output of the
listcommand in the example.