pub struct USBDevice {
Show 18 fields pub name: String, pub vendor_id: Option<u16>, pub product_id: Option<u16>, pub location_id: DeviceLocation, pub serial_num: Option<String>, pub manufacturer: Option<String>, pub bcd_device: Option<Version>, pub bcd_usb: Option<Version>, pub bus_power: Option<u16>, pub bus_power_used: Option<u16>, pub device_speed: Option<DeviceSpeed>, pub extra_current_used: Option<u16>, pub devices: Option<Vec<USBDevice>>, pub class: Option<ClassCode>, pub sub_class: Option<u8>, pub protocol: Option<u8>, pub extra: Option<USBDeviceExtra>, pub profiler_error: Option<String>,
}
Expand description

USB device data based on JSON object output from system_profiler but now used for other platforms

Desgined to hold static data for the device, obtained from system_profiler Deserializer or cyme::lsusb. Fields should probably be non-pub with getters/setters but treat them as read-only.

Fields§

§name: String

The device product name as reported in descriptor or using usb_ids if None

§vendor_id: Option<u16>

Unique vendor identifier - purchased from USB IF

§product_id: Option<u16>

Vendor unique product identifier

§location_id: DeviceLocation

DeviceLocation information of position within bus

§serial_num: Option<String>

Device serial number as reported by descriptor

§manufacturer: Option<String>

The device manufacturer as provided in descriptor or using usb_ids if None

§bcd_device: Option<Version>

The device release number set by the developer as a Version

§bcd_usb: Option<Version>

The highest version of USB the device supports as a Version

§bus_power: Option<u16>

macOS system_profiler only - actually bus current in mA not power!

§bus_power_used: Option<u16>

macOS system_profiler only - actually bus current used in mA not power!

§device_speed: Option<DeviceSpeed>

Advertised device capable speed

§extra_current_used: Option<u16>

macOS system_profiler only - actually bus current used in mA not power!

§devices: Option<Vec<USBDevice>>

Devices can be hub and have devices attached so need to walk each device’s devices…

§class: Option<ClassCode>

USB device class

§sub_class: Option<u8>

USB sub-class

§protocol: Option<u8>

USB protocol

§extra: Option<USBDeviceExtra>

Extra data obtained by libusb/udev exploration

§profiler_error: Option<String>

Internal to store any non-critical errors captured whilst profiling, unable to open for example

Implementations§

source§

impl USBDevice

source

pub fn has_devices(&self) -> bool

Does the device have child devices; devices is Some and > 0

source

pub fn has_interface_class(&self, c: &ClassCode) -> bool

Does the device have an interface with class

source

pub fn get_root_hub(&self) -> Option<&USBDevice>

Gets root_hub USBDevice if it is one

root_hub returns Some(Self)

let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.get_root_hub().is_some(), true);

Not a root_hub returns None

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.get_root_hub().is_some(), false);
source

pub fn get_node(&self, port_path: &str) -> Option<&USBDevice>

Recursively walk all USBDevice from self, looking for the one with port_path and returning reference

Will panic if port_path is not a child device or if it sits shallower than self

source

pub fn get_node_mut(&mut self, port_path: &str) -> Option<&mut USBDevice>

Recursively walk all USBDevice from self, looking for the one with port_path and returning mutable

Will panic if port_path is not a child device or if it sits shallower than self

source

pub fn get_branch_position(&self) -> u8

Returns position on branch (parent), which is the last number in tree_positions also sometimes refered to as port

source

pub fn get_depth(&self) -> usize

The number of USBDevice deep; branch depth

source

pub fn is_hub(&self) -> bool

Returns true if device is a hub based on device name - not perfect but most hubs advertise as a hub in name - or class code if it has one

// hub in name
let d = cyme::system_profiler::USBDevice{ name: String::from("My special hub"), ..Default::default() };
assert_eq!(d.is_hub(), true);

// Class is hub
let d = cyme::system_profiler::USBDevice{ name: String::from("Not named but Class"), class: Some(cyme::usb::ClassCode::Hub),  ..Default::default() };
assert_eq!(d.is_hub(), true);

// not a hub
let d = cyme::system_profiler::USBDevice{ name: String::from("My special device"), ..Default::default() };
assert_eq!(d.is_hub(), false);
source

pub fn port_path(&self) -> String

Linux style port path where it can be found on system device path - normaly /sys/bus/usb/devices

Normal device

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.port_path(), "1-1.2.3");

Get a root_hub port path

let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.port_path(), "1-0:1.0");
source

pub fn parent_path(&self) -> Result<String, Error>

Path of parent USBDevice; one above in tree

Device with parent

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.parent_path(), Ok(String::from("1-1.2")));

Trunk device parent is path to bus

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.parent_path(), Ok(String::from("1-0")));

Cannot get parent for root_hub

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.parent_path().is_err(), true);
source

pub fn trunk_path(&self) -> String

Path of trunk USBDevice; first in tree

let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2, 3] }, ..Default::default() };
assert_eq!(d.trunk_path(), "1-1");
source

pub fn dev_path(&self) -> String

Linux devpath to USBDevice

source

pub fn is_trunk_device(&self) -> bool

Trunk device is first in tree

// trunk device only 1 position in tree
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.is_trunk_device(), true);

// not a trunk device
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1, 2] }, ..Default::default() };
assert_eq!(d.is_trunk_device(), false);
source

pub fn is_root_hub(&self) -> bool

Root hub is a specific device on Linux, essentially the bus but sits in device tree because of system_profiler legacy

// a root hub no tree positions
let d = cyme::system_profiler::USBDevice{ name: String::from("root_hub"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![] }, ..Default::default() };
assert_eq!(d.is_root_hub(), true);

// not a root hub has tree positions
let d = cyme::system_profiler::USBDevice{ name: String::from("Test device"), location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 0, tree_positions: vec![1] }, ..Default::default() };
assert_eq!(d.is_root_hub(), false);
source

pub fn get_vendor_product_with_fallback(&self) -> (String, String)

From lsusb.c: Attempt to get friendly vendor and product names from the udev hwdb. If either or both are not present, instead populate those from the device’s own string descriptors

source

pub fn to_lsusb_string(&self) -> String

Generate a String from self like lsusb default list device

let d = cyme::system_profiler::USBDevice{
    name: String::from("Test device"),
    manufacturer: Some(String::from("Test Devices Inc.")),
    vendor_id: Some(0x1234),
    product_id: Some(0x4321),
    location_id: cyme::system_profiler::DeviceLocation { bus: 1, number: 4, tree_positions: vec![1, 2, 3] },
    ..Default::default()
    };
assert_eq!(d.to_lsusb_string(), "Bus 001 Device 004: ID 1234:4321 Test Devices Inc. Test device");
source

pub fn to_lsusb_tree_string(&self) -> Vec<(String, String, String)>

Generate a tuple (String, String, String) of the lsusb tree output at all three verbosity levels

Trait Implementations§

source§

impl Block<DeviceBlocks, USBDevice> for DeviceBlocks

source§

fn default_blocks(verbose: bool) -> Vec<Self>

List of default blocks to use for printing T with optional verbose for maximum verbosity
source§

fn len(&self, d: &[&USBDevice]) -> usize

Returns the length of block value given device data - like block_length but actual device field length rather than fixed/heading
source§

fn generate_padding(d: &[&USBDevice]) -> HashMap<Self, usize>

Creates a HashMap of B keys to usize of longest value for that key in the d Vec or heading if > this; values can then be padded to match this
source§

fn format_value( &self, d: &USBDevice, pad: &HashMap<Self, usize>, settings: &PrintSettings ) -> Option<String>

Formats the value associated with the block into a display String
source§

fn colour(&self, s: &str, ct: &ColourTheme) -> ColoredString

Colour the block String
source§

fn heading(&self) -> &str

Creates the heading for the block value, for use with the heading flag
source§

fn heading_padded(&self, pad: &HashMap<Self, usize>) -> String

Pads the heading with provided padding block HashMap
source§

fn block_length(&self) -> BlockLength

Returns length type and usize contained, BlockLength::Variable will be heading usize without actual device data
source§

fn is_icon(&self) -> bool

If the block is used for icons
source§

const INSET: u8 = 0u8

The inset when printing non-tree as a list
source§

fn value_is_variable_length(&self) -> bool

Returns whether the value intended for the block is a variable length type (string descriptor)
source§

fn format_base_u16(v: u16, settings: &PrintSettings) -> String

Formats u16 values like VID as base16 or base10 depending on decimal setting
source§

fn format_base_u8(v: u8, settings: &PrintSettings) -> String

Formats u8 values like codes as base16 or base10 depending on decimal setting
source§

impl Clone for USBDevice

source§

fn clone(&self) -> USBDevice

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for USBDevice

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for USBDevice

source§

fn default() -> USBDevice

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for USBDevice

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for USBDevice

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Serialize for USBDevice

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,