Crates.io | yusb |
lib.rs | yusb |
version | 0.1.2 |
source | src |
created_at | 2023-07-09 14:50:06.501145 |
updated_at | 2023-10-18 15:29:20.529233 |
description | Rust library for accessing USB devices. |
homepage | https://github.com/fpagliughi/yusb |
repository | https://github.com/fpagliughi/yusb.git |
max_upload_size | |
id | 912101 |
size | 239,231 |
Yet another fork of a fork of a Rust libusb wrapper!
Pronounced yoo-ess-bee.
This is an update to Ilya Averyanov's rusb crate, which itself is a fork of David Cuddeback's libusb crate.
The initial versions of this crate differ from rusb
in a number of ways:
UsbContext
trait
Context
and GenericContext
types into a single, concrete Context
type.Context
with a null inner pointer.Device<T>
and DeviceList<T>
no longer need to be generic over the Context
type (since there is now only a single context type), and are now just Device
and DeviceList
, respectively.Port
type which uniquely identified the physical USB port to which a device in the system is attached.
Speed
type updated:
if (device.speed() < Speed::Super) { println!("Plug the device into a faster port");
DeviceList
implements IntoIterator
so can be used directly by for loops without .iter()
This crate provides a safe wrapper around the native libusb
library. It applies the RAII pattern
and Rust lifetimes to ensure safe usage of all libusb
functionality. The RAII pattern ensures that
all acquired resources are released when they're no longer needed, and Rust lifetimes ensure that
resources are released in a proper order.
To use yusb, no extra setup is required as yusb will automatically download the source for libusb and build it.
However if building libusb fails you can also try setting up the native libusb
library where it can
be found by pkg-config
or vcpkg
.
All systems supported by the native libusb
library are also supported by the libusb
crate. It's
been tested on Linux, OS X, and Windows.
The yusb
crate can be used when cross-compiling to a foreign target. Details on how to
cross-compile yusb
are explained in the libusb1-sys
crate's
README.
Add yusb
as a dependency in Cargo.toml
:
[dependencies]
yusb = "0.1"
Import the yusb
crate. The starting point for nearly all yusb
functionality is to create a
context object. With a context object, you can list devices, read their descriptors, open them, and
communicate with their endpoints:
fn main() {
for device in yusb::devices().unwrap().iter() {
let device_desc = device.device_descriptor().unwrap();
println!("Bus {:03} Device {:03} ID {:04x}:{:04x}",
device.bus_number(),
device.address(),
device_desc.vendor_id(),
device_desc.product_id());
}
}
Distributed under the MIT License.
If you link native libusb
(by example using vendored
features) library statically then
you must follow GNU LGPL from libusb.