MCPcopy Index your code
hub / github.com/dcuddeback/libusb-rs

github.com/dcuddeback/libusb-rs @v0.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.0 ↗ · + Follow
469 symbols 587 edges 17 files 110 documented · 23%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Libusb

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

In order to use the libusb crate, you must have the native libusb library installed where it can be found by pkg-config.

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 libusb crate can be used when cross-compiling to a foreign target. Details on how to cross-compile libusb are explained in the libusb-sys crate's README.

Usage

Add libusb as a dependency in Cargo.toml:

[dependencies]
libusb = "0.3"

Import the libusb crate. The starting point for nearly all libusb 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:

extern crate libusb;

fn main() {
    let mut context = libusb::Context::new().unwrap();

    for mut device in context.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());
    }
}

Contributors

License

Copyright © 2015 David Cuddeback

Distributed under the MIT License.

Core symbols most depended-on inside this repo

len
called by 12
src/device_list.rs
from_libusb
called by 7
src/device_handle.rs
iter
called by 6
src/device_list.rs
read_string_descriptor
called by 5
src/device_handle.rs
set_log_level
called by 5
src/context.rs
from_libusb
called by 4
src/device.rs
descriptors
called by 3
src/interface_descriptor.rs
endpoint_descriptors
called by 3
src/interface_descriptor.rs

Shape

Function 330
Method 110
Class 18
Enum 11

Languages

Rust100%

Modules by API surface

src/language.rs252 symbols
src/fields.rs32 symbols
src/device_descriptor.rs30 symbols
src/interface_descriptor.rs28 symbols
src/device_handle.rs26 symbols
src/config_descriptor.rs22 symbols
src/endpoint_descriptor.rs20 symbols
src/context.rs12 symbols
src/device.rs10 symbols
src/version.rs8 symbols
src/device_list.rs8 symbols
examples/list_devices.rs8 symbols

For agents

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

⬇ download graph artifact

Ask about this repo answers extend the page