MCPcopy Index your code
hub / github.com/a1ien/rusb

github.com/a1ien/rusb @v0.9.4-rusb

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.4-rusb ↗ · + Follow
639 symbols 904 edges 28 files 161 documented · 25% updated 6mo ago★ 49517 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Rusb

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.

Dependencies

To use rusb no extra setup is required as rusb 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.

Cross-Compiling

The rusb crate can be used when cross-compiling to a foreign target. Details on how to cross-compile rusb are explained in the libusb1-sys crate's README.

Usage

Add rusb as a dependency in Cargo.toml:

[dependencies]
rusb = "0.9"

Import the rusb crate. The starting point for nearly all rusb 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 rusb::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());
    }
}

License

Distributed under the MIT License.

License note.

If you link native libusb (by example using vendored features) library statically then you must follow GNU LGPL from libusb.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 399
Method 177
Class 48
Enum 13
Interface 2

Languages

Rust100%

Modules by API surface

src/language.rs252 symbols
src/device_handle.rs52 symbols
src/fields.rs35 symbols
src/device_descriptor.rs32 symbols
libusb1-sys/src/lib.rs32 symbols
src/interface_descriptor.rs31 symbols
src/config_descriptor.rs27 symbols
src/endpoint_descriptor.rs25 symbols
src/context.rs25 symbols
libusb1-sys/examples/ffi_list_devices.rs18 symbols
src/device.rs17 symbols
src/hotplug.rs14 symbols

For agents

$ claude mcp add rusb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page