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: StringThe 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: DeviceLocationDeviceLocation 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: InternalDataInternal data for cyme
Implementations§
Source§impl Device
impl Device
Sourcepub fn has_devices(&self) -> bool
pub fn has_devices(&self) -> bool
Does the device have child devices; devices is Some and > 0
Sourcepub fn has_interface_class(&self, c: &BaseClass) -> bool
pub fn has_interface_class(&self, c: &BaseClass) -> bool
Does the device have an interface with class
Sourcepub fn get_root_hub(&self) -> Option<&Device>
pub fn get_root_hub(&self) -> Option<&Device>
Gets root_hub Device if it is one
Sourcepub fn get_root_hub_mut(&mut self) -> Option<&mut Device>
pub fn get_root_hub_mut(&mut self) -> Option<&mut Device>
Gets mutable root_hub Device if it is one
Sourcepub fn get_node_mut(&mut self, port_path: &PortPath) -> Option<&mut Device>
pub fn get_node_mut(&mut self, port_path: &PortPath) -> Option<&mut Device>
Sourcepub fn get_node_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Device>
pub fn get_node_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Device>
Find the Device by it’s Path
Sourcepub fn get_node_mut_by_path<P: AsRef<Path>>(
&mut self,
path: P,
) -> Option<&mut Device>
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
Sourcepub fn get_node_by_str(&self, path: &str) -> Option<&Device>
pub fn get_node_by_str(&self, path: &str) -> Option<&Device>
Search for reference to Device at port path as string
Sourcepub fn get_node_str_mut(&mut self, path: &str) -> Option<&mut Device>
pub fn get_node_str_mut(&mut self, path: &str) -> Option<&mut Device>
Search for mutable reference to Device at port path as string
Sourcepub fn get_config(&self, config: u8) -> Option<&Configuration>
pub fn get_config(&self, config: u8) -> Option<&Configuration>
Get the Configuration with number config from the device’s extra data
Sourcepub fn get_config_mut(&mut self, config: u8) -> Option<&mut Configuration>
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
Sourcepub fn get_interface(
&self,
config: u8,
interface: u8,
alt_setting: u8,
) -> Option<&Interface>
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
Sourcepub fn get_interface_mut(
&mut self,
config: u8,
interface: u8,
alt_setting: u8,
) -> Option<&mut Interface>
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
Sourcepub fn get_endpoint(
&self,
config: u8,
interface: u8,
alt_setting: u8,
endpoint_address: u8,
) -> Option<&Endpoint>
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
Sourcepub fn get_endpoint_mut(
&mut self,
config: u8,
interface: u8,
alt_setting: u8,
endpoint_address: u8,
) -> Option<&mut Endpoint>
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
Sourcepub fn get_branch_position(&self) -> u8
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
Sourcepub fn is_hub(&self) -> bool
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
Sourcepub fn sysfs_path(&self) -> PathBuf
pub fn sysfs_path(&self) -> PathBuf
Linux style port path where it can be found on system device path - normally /sys/bus/usb/devices
Sourcepub fn parent_port_path(&self) -> Option<PortPath>
pub fn parent_port_path(&self) -> Option<PortPath>
Sourcepub fn trunk_port_path(&self) -> PortPath
pub fn trunk_port_path(&self) -> PortPath
Sourcepub fn sysfs_name(&self) -> String
pub fn sysfs_name(&self) -> String
Linux sysfs name of Device
Sourcepub fn is_trunk_device(&self) -> bool
pub fn is_trunk_device(&self) -> bool
Trunk device is first in tree
Sourcepub fn is_root_hub(&self) -> bool
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
Sourcepub fn get_vendor_product_with_fallback(&self) -> (String, String)
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
Sourcepub fn to_lsusb_string(&self) -> String
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");Sourcepub fn to_lsusb_tree_strings(&self, verbosity: u8) -> Vec<Vec<String>>
pub fn to_lsusb_tree_strings(&self, verbosity: u8) -> Vec<Vec<String>>
Generate a Vec of Vec
Each device contains of Vec
Sourcepub fn base_class_code(&self) -> Option<u8>
pub fn base_class_code(&self) -> Option<u8>
Gets the base class code byte from BaseClass
Sourcepub fn class_name(&self) -> Option<&str>
pub fn class_name(&self) -> Option<&str>
Name of class from Linux USB IDs repository
Sourcepub fn sub_class_name(&self) -> Option<&str>
pub fn sub_class_name(&self) -> Option<&str>
Name of sub class from Linux USB IDs repository
Sourcepub fn protocol_name(&self) -> Option<&str>
pub fn protocol_name(&self) -> Option<&str>
Name of protocol from Linux USB IDs repository
Sourcepub fn fully_defined_class(&self) -> Option<ClassCode>
pub fn fully_defined_class(&self) -> Option<ClassCode>
Returns fully defined USB [Class] based on base_class, sub_class and protocol triplet
Sourcepub fn flatten(&self) -> Vec<&Device>
pub fn flatten(&self) -> Vec<&Device>
Recursively gets all devices in a Device and flattens them into a Vec of references, including self
Sourcepub fn flatten_mut(&mut self) -> Vec<&mut Device>
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
Sourcepub fn into_flattened(self) -> Vec<Device>
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
Sourcepub fn get_id(&self, id: &DeviceId) -> Option<&Self>
pub fn get_id(&self, id: &DeviceId) -> Option<&Self>
Recursively searches for a device with a specific ::nusb::DeviceId and returns a reference
Sourcepub fn get_id_mut(&mut self, id: &DeviceId) -> Option<&mut Self>
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
Sourcepub fn last_event(&self) -> Option<DeviceEvent>
pub fn last_event(&self) -> Option<DeviceEvent>
Get last event that occurred on device
Sourcepub fn is_disconnected(&self) -> bool
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
Should the device be hidden when printing
Sourcepub fn is_expanded(&self) -> bool
pub fn is_expanded(&self) -> bool
Should the device be displayed expanded in a tree
Sourcepub fn toggle_expanded(&mut self)
pub fn toggle_expanded(&mut self)
Toggle the expanded state of the device
Sourcepub fn set_all_expanded(&mut self, expanded: bool)
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
impl Block<DeviceBlocks, Device> for DeviceBlocks
Source§fn default_blocks(verbose: bool) -> Vec<Self>
fn default_blocks(verbose: bool) -> Vec<Self>
verbose for maximum verbositySource§fn example_blocks() -> Vec<Self>
fn example_blocks() -> Vec<Self>
Source§fn len(&self, d: &[&Device]) -> usize
fn len(&self, d: &[&Device]) -> usize
Source§fn generate_padding(d: &[&Device]) -> HashMap<Self, usize>
fn generate_padding(d: &[&Device]) -> HashMap<Self, usize>
d Vec or heading if > this; values can then be padded to match thisSource§fn format_value(
&self,
d: &Device,
pad: &HashMap<Self, usize>,
settings: &PrintSettings,
) -> Option<String>
fn format_value( &self, d: &Device, pad: &HashMap<Self, usize>, settings: &PrintSettings, ) -> Option<String>
Source§fn colour(&self, s: &str, ct: &ColourTheme) -> ColoredString
fn colour(&self, s: &str, ct: &ColourTheme) -> ColoredString
Source§fn heading(&self) -> &str
fn heading(&self) -> &str
Source§fn heading_padded(&self, pad: &HashMap<Self, usize>) -> String
fn heading_padded(&self, pad: &HashMap<Self, usize>) -> String
Source§fn block_length(&self) -> BlockLength
fn block_length(&self) -> BlockLength
BlockLength::Variable will be heading usize without actual device dataSource§fn value_is_variable_length(&self) -> bool
fn value_is_variable_length(&self) -> bool
Source§fn format_base_u16(v: u16, settings: &PrintSettings) -> String
fn format_base_u16(v: u16, settings: &PrintSettings) -> String
Source§fn format_base_u8(v: u8, settings: &PrintSettings) -> String
fn format_base_u8(v: u8, settings: &PrintSettings) -> String
Source§fn format_vidpid(
v: Option<u16>,
p: Option<u16>,
settings: &PrintSettings,
) -> String
fn format_vidpid( v: Option<u16>, p: Option<u16>, settings: &PrintSettings, ) -> String
Source§fn all_blocks() -> &'static [B]where
Self: Sized,
fn all_blocks() -> &'static [B]where
Self: Sized,
Source§impl<'de> Deserialize<'de> for Device
impl<'de> Deserialize<'de> for Device
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&BusInfo> for Device
Convert a bus into a root hub device - following the same sort of abstraction as Linux
impl From<&BusInfo> for Device
Convert a bus into a root hub device - following the same sort of abstraction as Linux
Source§impl From<&DeviceInfo> for Device
impl From<&DeviceInfo> for Device
Source§fn from(device_info: &DeviceInfo) -> Self
fn from(device_info: &DeviceInfo) -> Self
Source§impl<'a> IntoIterator for &'a Device
impl<'a> IntoIterator for &'a Device
Source§impl<'a> IntoIterator for &'a mut Device
impl<'a> IntoIterator for &'a mut Device
Auto Trait Implementations§
impl Freeze for Device
impl RefUnwindSafe for Device
impl Send for Device
impl Sync for Device
impl Unpin for Device
impl UnsafeUnpin for Device
impl UnwindSafe for Device
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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