Struct Context

Source
pub struct Context { /* private fields */ }
Expand description

A libusb context.

Implementations§

Source§

impl Context

Source

pub fn new() -> Result<Self>

Opens a new libusb context.

Source

pub fn set_log_level(&mut self, level: LogLevel)

Sets the log level of a libusb context.

Source

pub fn has_capability(&self) -> bool

Source

pub fn has_hotplug(&self) -> bool

Tests whether the running libusb library supports hotplug.

Source

pub fn has_hid_access(&self) -> bool

Tests whether the running libusb library has HID access.

Source

pub fn supports_detach_kernel_driver(&self) -> bool

Tests whether the running libusb library supports detaching the kernel driver.

Source

pub fn devices<'a>(&'a self) -> Result<DeviceList<'a>>

Returns a list of the current USB devices. The context must outlive the device list.

Source

pub fn open_device_with_vid_pid( &self, vendor_id: u16, product_id: u16, ) -> Option<DeviceHandle<'_>>

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.

Source

pub fn register_callback( &self, vendor_id: Option<u16>, product_id: Option<u16>, class: Option<u8>, callback: Box<dyn Hotplug>, ) -> Result<Registration>

Source

pub fn unregister_callback(&self, reg: Registration)

TODO: fix handler leak

Source

pub fn handle_events(&self, timeout: Option<Duration>) -> Result<()>

Trait Implementations§

Source§

impl Drop for Context

Source§

fn drop(&mut self)

Closes the libusb context.

Source§

impl Send for Context

Source§

impl Sync for Context

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.