Code Monkey home page Code Monkey logo

rusb's Introduction

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.

rusb's People

Contributors

a1ien avatar adaszko avatar albertogp avatar ammubhave avatar anton-dutov avatar arkpar avatar avantgardnerio avatar cu3po42 avatar cujomalainey avatar danielsel avatar dcuddeback avatar debris avatar detly avatar djanderson avatar elfmimi avatar elmarco avatar fpagliughi avatar jonas-schievink avatar kevinmehall avatar lespea avatar newam avatar otavio avatar pantsman0 avatar patrickelectric avatar pheki avatar saethlin avatar serpilliere avatar tanriol avatar tiwalun avatar xanderio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.