Skip to main content

Device

Struct Device 

Source
pub struct Device {
Show 21 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<Device>>, pub class: Option<BaseClass>, pub sub_class: Option<u8>, pub protocol: Option<u8>, pub extra: Option<DeviceExtra>, pub profiler_error: Option<String>, pub id: Option<DeviceId>, pub last_event: Option<DeviceEvent>, pub internal: InternalData,
}
Expand description

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

Designed 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

See DeviceExtra for negotiated speed

§extra_current_used: Option<u16>

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

§devices: Option<Vec<Device>>

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

§class: Option<BaseClass>

USB device class

§sub_class: Option<u8>

USB sub-class

§protocol: Option<u8>

USB protocol

§extra: Option<DeviceExtra>

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

§id: Option<DeviceId>

Unique ID assigned by system

§last_event: Option<DeviceEvent>

Last event that occurred on device

§internal: InternalData

Internal data for cyme

Implementations§

Source§

impl Device

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: &BaseClass) -> bool

Does the device have an interface with class

Source

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

Gets root_hub Device if it is one

Source

pub fn get_root_hub_mut(&mut self) -> Option<&mut Device>

Gets mutable root_hub Device if it is one

Source

pub fn get_node(&self, port_path: &PortPath) -> Option<&Device>

Recursively walk all Device from self, looking for the one with PortPath and returning reference

Source

pub fn get_node_mut(&mut self, port_path: &PortPath) -> Option<&mut Device>

Recursively walk all Device from self, looking for the one with PortPath and returning mutable

Source

pub fn get_node_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Device>

Find the Device by it’s Path

Source

pub fn get_node_mut_by_path<P: AsRef<Path>>( &mut self, path: P, ) -> Option<&mut Device>

Find the mutable Device by it’s Path

Source

pub fn get_node_by_str(&self, path: &str) -> Option<&Device>

Search for reference to Device at port path as string

Source

pub fn get_node_str_mut(&mut self, path: &str) -> Option<&mut Device>

Search for mutable reference to Device at port path as string

Source

pub fn get_config(&self, config: u8) -> Option<&Configuration>

Get the Configuration with number config from the device’s extra data

Source

pub fn get_config_mut(&mut self, config: u8) -> Option<&mut Configuration>

Get the mutable Configuration with number config from the device’s extra data

Source

pub fn get_interface( &self, config: u8, interface: u8, alt_setting: u8, ) -> Option<&Interface>

Get the Interface with number interface from the device’s extra data

Source

pub fn get_interface_mut( &mut self, config: u8, interface: u8, alt_setting: u8, ) -> Option<&mut Interface>

Get the mutable Interface with number interface from the device’s extra data

Source

pub fn get_endpoint( &self, config: u8, interface: u8, alt_setting: u8, endpoint_address: u8, ) -> Option<&Endpoint>

Get the Endpoint with number endpoint from the device’s extra data

Source

pub fn get_endpoint_mut( &mut self, config: u8, interface: u8, alt_setting: u8, endpoint_address: u8, ) -> Option<&mut Endpoint>

Get the mutable Endpoint with number endpoint from the device’s extra data

Source

pub fn get_branch_position(&self) -> u8

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

Source

pub fn get_depth(&self) -> usize

The number of Device 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

Source

pub fn port_path(&self) -> PortPath

Source

pub fn sysfs_path(&self) -> PathBuf

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

Source

pub fn parent_port_path(&self) -> Option<PortPath>

PortPath of parent Device; one above in tree

Source

pub fn trunk_port_path(&self) -> PortPath

PortPath of trunk Device; first in tree

Source

pub fn dev_path(&self) -> PathBuf

Linux devpath to Device

Source

pub fn sysfs_name(&self) -> String

Linux sysfs name of Device

Source

pub fn is_trunk_device(&self) -> bool

Trunk device is first in tree

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

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::profiler::Device{
    name: String::from("Test device"),
    manufacturer: Some(String::from("Test Devices Inc.")),
    vendor_id: Some(0x1234),
    product_id: Some(0x4321),
    location_id: cyme::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_strings(&self, verbosity: u8) -> Vec<Vec<String>>

Generate a Vec of Vec from self like lsusb tree mode in order of verbosity

Each device contains of Vec of interfaces

Source

pub fn base_class_code(&self) -> Option<u8>

Gets the base class code byte from BaseClass

Source

pub fn class_name(&self) -> Option<&str>

Name of class from Linux USB IDs repository

Source

pub fn sub_class_name(&self) -> Option<&str>

Name of sub class from Linux USB IDs repository

Source

pub fn protocol_name(&self) -> Option<&str>

Name of protocol from Linux USB IDs repository

Source

pub fn fully_defined_class(&self) -> Option<ClassCode>

Returns fully defined USB [Class] based on base_class, sub_class and protocol triplet

Source

pub fn flatten(&self) -> Vec<&Device>

Recursively gets all devices in a Device and flattens them into a Vec of references, including self

Source

pub fn flatten_mut(&mut self) -> Vec<&mut Device>

Recursively gets all devices in a Device and flattens them into a Vec of mutable references, excluding self

Source

pub fn into_flattened(self) -> Vec<Device>

Recursively gets all devices in a Device and flattens them into a Vec, including self

Similar to flatten but flattens in place rather than returning references so is destructive

Source

pub fn get_id(&self, id: &DeviceId) -> Option<&Self>

Recursively searches for a device with a specific ::nusb::DeviceId and returns a reference

Source

pub fn get_id_mut(&mut self, id: &DeviceId) -> Option<&mut Self>

Recursively searches for a device with a specific ::nusb::DeviceId and returns a mutable reference

Source

pub fn last_event(&self) -> Option<DeviceEvent>

Get last event that occurred on device

Source

pub fn is_disconnected(&self) -> bool

Has the device disconnected based last event being disconnected

Logic rather than is_connected since Profiled event is not certain still present

Source

pub fn is_hidden(&self) -> bool

Should the device be hidden when printing

Source

pub fn is_expanded(&self) -> bool

Should the device be displayed expanded in a tree

Source

pub fn toggle_expanded(&mut self)

Toggle the expanded state of the device

Source

pub fn set_all_expanded(&mut self, expanded: bool)

Set the expanded state of the device and all configurations, interfaces and endpoints

Trait Implementations§

Source§

impl Block<DeviceBlocks, Device> 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 example_blocks() -> Vec<Self>

Example blocks for generated files
Source§

fn len(&self, d: &[&Device]) -> 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: &[&Device]) -> 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: &Device, 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 = 0

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§

fn format_vidpid( v: Option<u16>, p: Option<u16>, settings: &PrintSettings, ) -> String

Formats VID and PID values into a string like “vid:pid” with padding
Source§

fn all_blocks() -> &'static [B]
where Self: Sized,

Get static array of all blocks for this type
Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

Returns a duplicate 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 Device

Source§

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

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

impl Default for Device

Source§

fn default() -> Device

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

impl<'de> Deserialize<'de> for Device

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 Device

Source§

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

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

impl From<&BusInfo> for Device

Convert a bus into a root hub device - following the same sort of abstraction as Linux

Source§

fn from(bus: &BusInfo) -> Self

Converts to this type from the input type.
Source§

impl From<&DeviceInfo> for Device

Source§

fn from(device_info: &DeviceInfo) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Device

Source§

type Item = &'a Device

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<&'a Device as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<Self::Item>

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut Device

Source§

type Item = &'a mut Device

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<&'a mut Device as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<Self::Item>

Creates an iterator from a value. Read more
Source§

impl PartialEq for Device

Available on crate feature nusb only.
Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Device

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

impl TryFrom<Device> for Bus

Source§

type Error = Error

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

fn try_from(device: Device) -> Result<Self>

Performs the conversion.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

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