Make USB device config public#69
Open
nickray wants to merge 1 commit intorust-embedded-community:masterfrom
Open
Make USB device config public#69nickray wants to merge 1 commit intorust-embedded-community:masterfrom
nickray wants to merge 1 commit intorust-embedded-community:masterfrom
Conversation
ryan-summers
reviewed
Apr 8, 2023
Comment on lines
+18
to
+47
| pub struct Config<'a> { | ||
| /// USB device class | ||
| pub device_class: u8, | ||
| /// USB device subclass | ||
| pub device_sub_class: u8, | ||
| /// USB device protocol | ||
| pub device_protocol: u8, | ||
| /// USB control endpoint maximum packet size | ||
| pub max_packet_size_0: u8, | ||
| /// USB vendor ID | ||
| pub vendor_id: u16, | ||
| /// USB product ID | ||
| pub product_id: u16, | ||
| /// BCD encoded device release | ||
| pub device_release: u16, | ||
| /// Manufacturer string | ||
| pub manufacturer: Option<&'a str>, | ||
| /// Product string | ||
| pub product: Option<&'a str>, | ||
| /// Serial number | ||
| pub serial_number: Option<&'a str>, | ||
| /// Is device self-powered? | ||
| pub self_powered: bool, | ||
| /// Does device support remote wakeup? | ||
| pub supports_remote_wakeup: bool, | ||
| /// Is device composite with IADs? | ||
| pub composite_with_iads: bool, | ||
| /// Maximum power consumption of device | ||
| pub max_power: u8, | ||
| } |
Member
There was a problem hiding this comment.
As much as I like the builder semantics, making struct fields public is problematic . See https://rust-lang.github.io/api-guidelines/future-proofing.html#structs-have-private-fields-c-struct-private for a discussion on why this is problematic for a maintainability perspective.
Other than that, I like the builder config API
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.
I was about to start tackling USB/IP when I discovered @Sawchord's https://github.com/Sawchord/usbip-device.
For
usbip list -r localhostto be somewhat pretty, the USB/IP server should return basic info on the device, which duplicates the contents of the non-publicConfigstruct here. (It's not strictly necessary for this info to be correct, AFAIU.)Looking at UsbDeviceBuilder, in reality it's a ConfigBuilder, which would become quite redundant (candidate for deprecation?) if the config itself were made public with a fluent/builder interface. I'm gambling on increasing merge/publish potential by staying backwards compatible though :)
This would then allow re-use in the USB/IP driver (e.g. https://github.com/nickray/usbip-device/blob/7bab96f64072da82a552c94213b5dc98f2481c99/examples/twitching_mouse.rs#L16-L26)
There's a bit chicken+egg involved regarding DRY and the interface descriptors (which USB/IP also advertises); solving that seems it would require breaking changes which I don't want to propose.
P.S. Are there any/many useful cases for
Config<'a>with non-'staticlifetimes?