Skip to content

Mark rusb-async::{Error, Result} as public#220

Closed
bobozaur wants to merge 56 commits into
a1ien:rusb-asyncfrom
bobozaur:rusb-async
Closed

Mark rusb-async::{Error, Result} as public#220
bobozaur wants to merge 56 commits into
a1ien:rusb-asyncfrom
bobozaur:rusb-async

Conversation

@bobozaur

@bobozaur bobozaur commented Apr 29, 2025

Copy link
Copy Markdown

Simple PR that rebases to latest changes and marks the crate specific Error and Result as public. This is particularly useful for matching on timeout errors for implementing async functions that can employ runtime specific sleep routines.

I saw there's also #217 which also addresses this but this is such a small change that could immediately be merged without waiting on PRs with broader scopes.

The PR additionally makes TransferPool::new() infallible, since it was returning a Result for no reason.

Fixes #160 .

ammubhave and others added 30 commits August 24, 2022 22:17
Make request_type function in fields.rs a const fn so that it can used
to create const global variables.

Test: The following code now compiles

```
const CTRL_OUT: u8 = request_type(
    rusb::Direction::Out,
    rusb::RequestType::Vendor,
    rusb::Recipient::Device,
);
```
fields.rs: Make request_type function a const fn
Before this commit, the lifetime of the endpoint descriptor was shorter
than the lifetime of the config descriptor, since it was tied to the
InterfaceDescriptor object. This commit amends the endpoint_descriptors
signature so that an EndpointDescriptor has the same lifetime as the
overarching ConfigDescriptor.

From my understanding, all state derived from a ConfigDescriptor has a
lifetime associated to that ConfigDescriptor. So, it's safe for the
EndpointDescriptor to adopt the ConfigDescriptor's lifetime through the
InterfaceDescriptor.

The new test shows us that the lifetimes are now all equal. This test
wouldn't compile without the signature change.
Increase endpoint descriptor's lifetime
Documentation specifies micros, but libusb consumes millis. Therefore passing in 1 micro results in an infinite timeout, not the shortest timeout.
…apability_descriptor

This fix adds missing fields to these two structs so that they can be
used from rust without the size mismatching from the C version.

See:
https://libusb.sourceforge.io/api-1.0/structlibusb__bos__descriptor.html
https://libusb.sourceforge.io/api-1.0/structlibusb__bos__dev__capability__descriptor.html
Add a function to disable device discovery
fix: 404 link for languages
Add serde support for public enums
rusb 0.9.3
Prepare release for rusb 0.9.3
Change the following methods to accept a non-exclusive reference:
- DeviceHandle::set_active_configuration
- DeviceHandle::unconfigure
- DeviceHandle::reset
- DeviceHandle::clear_halt
- DeviceHandle::detach_kernel_driver
- DeviceHandle::attach_kernel_driver
- DeviceHandle::set_auto_detach_kernel_driver
- DeviceHandle::claim_interface
- DeviceHandle::release_interface
- DeviceHandle::set_alternate_setting

This is safe to do because libusb is thread-safe.

Fixes a1ien#148
bLength, bDescriptorType and wTotalLength to descriptors
Use &self reference for all DeviceHandle methods
I and @dragonmux found two issues when building libusb from a MSVC host
to a MinGW target. When the build.rs script is built for the MSVC host,

- the vcpkg crate is used for detection (which correctly detects the
  MinGW target and reports an unsupported ABI)
- a MSVC flag is applied to the build (and thus breaking the build
  altogether)

This commit fixes both issues by changing vcpkg to a Windows-wide
dependency, and then if CARGO_CFG_TARGET_ENV is indeed MSVC, it is used
and the /source-charset:utf-8 flag is applied.
dmitry-zakablukov and others added 26 commits February 28, 2024 12:12
Some USB classes (UVC, UAC) provide alternate setting descriptors of interfaces with zero endpoints. Trying to call `endpoint_descriptors` on them caused a panic, because NULL was passed to `slice::from_raw_parts`. A branch was introduced to check for that case and create an iterator over an empty slice.

See: https://stackoverflow.com/a/49244874/2948315
…point-descriptors

fix: panic when trying to iterate over an interface with zero endpoints
Fix package detection and build when cross-compiling from MSVC to GNU
…iso_packet_desc (fixes a1ien#199)

This prevents panics on debug builds in new rust nightly versions (as of 2024-03-27), since they added bounds checks to `get_unchecked_mut`, which here was called on a zero-length slice representing a flexible array member. See: rust-lang/rust@2b43e75
Fixes a few macOS issues
Replace .get_unchecked_mut() with .as_mut_ptr().add() when accessing iso_packet_desc (fixes a1ien#199)
Add libusb_free_pollfds() in the available FFI methods.
…to-bos

fix: Add missing fields to libusb_bos_descriptor and libusb_bos_dev_capability_descriptor
libusb 0.7.0

* fix: Add missing fields to libusb_bos_descriptor and libusb_bos_dev_capability_descriptor
* Bump libusb to 1.0.27
* Remove unneeded mut

rusb 0.9.4

* bLength, bDescriptorType and wTotalLength to descriptors
* Use &self reference for all DeviceHandle methods
* fix: panic when trying to iterate over an interface with zero endpoints
* Log callback API added
* Bump libusb1-sys 0.7.0
Android does not have udev, but cross-compiling for Android on a Linux host with udev results in a udev link
Add libusb_init_context and associated structs
Android does not have udev; Do not link to udev on Android
Added new constructor for languages + tests
Co-authored-by: Ryan Butler <[email protected]>
Co-authored-by: Kevin Mehall <[email protected]>
@bobozaur

Copy link
Copy Markdown
Author

Closing in favor of #221 .

@bobozaur bobozaur closed this May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.