Trait rusb::UsbContext[][src]

pub trait UsbContext: Clone + Sized + Send + Sync {
    fn as_raw(&self) -> *mut libusb_context;

    fn devices(&self) -> Result<DeviceList<Self>> { ... }
fn open_device_with_vid_pid(
        &self,
        vendor_id: u16,
        product_id: u16
    ) -> Option<DeviceHandle<Self>> { ... }
unsafe fn open_device_with_fd(
        &self,
        fd: RawFd
    ) -> Result<DeviceHandle<Self>> { ... }
fn set_log_level(&mut self, level: LogLevel) { ... }
fn register_callback(
        &self,
        vendor_id: Option<u16>,
        product_id: Option<u16>,
        class: Option<u8>,
        callback: Box<dyn Hotplug<Self>>
    ) -> Result<Registration<Self>> { ... }
fn unregister_callback(&self, _reg: Registration<Self>) { ... }
fn handle_events(&self, timeout: Option<Duration>) -> Result<()> { ... }
fn interrupt_handle_events(&self) { ... }
fn next_timeout(&self) -> Result<Option<Duration>> { ... } }

Required methods

Get the raw libusb_context pointer, for advanced use in unsafe code.

Provided methods

Returns a list of the current USB devices.

Convenience function to open a device by its vendor ID and product ID.

This function is provided as a convenience for building prototypes without having to iterate a DeviceList. It is not meant for production applications.

Returns a device handle for the first device found matching vendor_id and product_id. On error, or if the device could not be found, it returns None.

Opens the device with a pre-opened file descriptor.

This is UNIX-only and platform-specific. It is currently working with Linux/Android, but might work with other systems in the future.

Note: This function does not take ownership of the specified file descriptor. The caller has the responsibility of keeping it opened for as long as the device handle.

Sets the log level of a libusb for context.

👎 Deprecated since 0.9.0:

Use HotplugBuilder

Register a callback to be called on hotplug events. The callback’s Hotplug::device_arrived method is called when a new device is added to the bus, and Hotplug::device_left is called when it is removed.

Devices can optionally be filtered by vendor (vendor_id) and device id (product_id).

The callback will remain registered until the returned Registration is dropped, which can be done explicitly with Context::unregister_callback.

When handling a Hotplug::device_arrived event it is considered safe to call any rusb function that takes a crate::Device. It also safe to open a device and submit asynchronous transfers. However, most other functions that take a DeviceHandle are not safe to call. Examples of such functions are any of the synchronous API functions or the blocking functions that retrieve various USB descriptors. These functions must be used outside of the context of the Hotplug functions.

Unregisters the callback corresponding to the given registration. The same thing can be achieved by dropping the registration.

Handle any pending events. If timeout less then 1 microseconds then this function will handle any already-pending events and then immediately return in non-blocking style. If timeout is None then function will handle any pending events in blocking mode.

Interrupt any active thread that is handling events (for example with handle_events).

Implementors