Skip to main content

Bus

Struct Bus 

Source
pub struct Bus {
    pub name: String,
    pub host_controller: String,
    pub host_controller_vendor: Option<String>,
    pub host_controller_device: Option<String>,
    pub pci_vendor: Option<u16>,
    pub pci_device: Option<u16>,
    pub pci_revision: Option<u16>,
    pub usb_bus_number: Option<u8>,
    pub devices: Option<Vec<Device>>,
    /* private fields */
}
Expand description

USB bus returned from system_profiler but now used for other platforms.

It is a merging of the PCI Host Controller information and root hub device data (if present). Essentially a root hub but not as a pseudo device but an explicit type - since the root hub is a bit confusing in that sense.

Fields§

§name: String

System internal bus name based on Root Hub device name

Normally something generic like ‘Root Hub’, ‘USB 3.0 Bus’

§host_controller: String

System internal bus provider name

§host_controller_vendor: Option<String>

Vendor name of PCI Host Controller from pci.ids

§host_controller_device: Option<String>

Device name of PCI Host Controller from pci.ids

§pci_vendor: Option<u16>

PCI vendor ID (VID)

§pci_device: Option<u16>

PCI device ID (PID)

§pci_revision: Option<u16>

PCI Revsision ID

§usb_bus_number: Option<u8>

Number of bus on system

§devices: Option<Vec<Device>>

Devices on the Bus. Since a device can have devices too, need to walk down all devices to get all devices on the bus

On Linux, the root hub is also included in this list

Implementations§

Source§

impl Bus

Returns of Vec of devices in the Bus as a reference

Source

pub fn len(&self) -> usize

Returns total number of devices in the bus

Source

pub fn into_flattened_devices(&mut self)

Flattens the bus by copying each device into a new devices Vec

Unlike the flattened_devices which returns references that may still contain a Vec of Device, this function makes those None too since it is doing a hard copy.

Not very pretty or efficient, probably a better way…

Source

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

Returns a flattened Vec of references to all Devices on the bus

Note that whilst Vec of references is flat, the Devices still contain a devices Vec where the references point; recursive functions on the returned Vec will produce weird results

Source

pub fn is_empty(&self) -> bool

Whether the bus has no Devices

Source

pub fn has_empty_hubs(&self) -> bool

Whether the bus has just empty hubs

Source

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

usb_bus_number is not always present in system_profiler output so try to get from first device instead

Source

pub fn path(&self) -> Option<PathBuf>

syspath style path to bus

Source

pub fn interface(&self) -> Option<DevicePath>

sysfs style path to bus interface

Source

pub fn remove_root_hub_device(&mut self)

Remove the root_hub if existing in bus

Source

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

Gets the device that is the root_hub associated with this bus - Linux only but exists in case of using –from-json

Source

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

Gets a mutable device that is the root_hub associated with this bus - Linux only but exists in case of using –from-json

Source

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

Search for Device in branches of bus and return reference

Source

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

Search for Device in branches of bus and return mutable if found

Source

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

Search for Device in branches of bus by Path and return reference

Source

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

Search for Device in branches of bus by Path and return mutable reference

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, port_path: &PortPath, config: u8, ) -> Option<&Configuration>

Get reference to Configuration at PortPath and config if present

Source

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

Get mutable reference to Configuration at PortPath and config if present

Source

pub fn get_interface(&self, device_path: &DevicePath) -> Option<&Interface>

Get reference to Interface at DevicePath if config and interface are present

Source

pub fn get_interface_mut( &mut self, device_path: &DevicePath, ) -> Option<&mut Interface>

Get mutable reference to Interface at DevicePath if config and interface are present

Source

pub fn get_endpoint(&self, endpoint_path: &EndpointPath) -> Option<&Endpoint>

Get reference to Endpoint at EndpointPath if config and interface are present

Source

pub fn get_endpoint_mut( &mut self, endpoint_path: &EndpointPath, ) -> Option<&mut Endpoint>

Get mutable reference to Endpoint at EndpointPath if config and interface are present

Source

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

Search for ::nusb::DeviceId in branches of bus and return reference

Source

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

Search for ::nusb::DeviceId in branches of bus and returns a mutable reference if found

Source

pub fn to_lsusb_string(&self) -> String

Generate a String from self like lsusb default list device

Source

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

Generate a Vec of Strings from self in lsusb tree self in order of verbosity

Only Linux systems with a root_hub will contain accurate data, others are mainly for styling

Source

pub fn is_hidden(&self) -> bool

Should the bus be hidden when printing

Source

pub fn is_expanded(&self) -> bool

Should the bus be expanded when printing

Source

pub fn toggle_expanded(&mut self)

Toggle the expanded state of the bus

Source

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

Set the expanded state of the bus and all devices

Trait Implementations§

Source§

impl Block<BusBlocks, Bus> for BusBlocks

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: &[&Bus]) -> 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: &[&Bus]) -> 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 colour(&self, s: &str, ct: &ColourTheme) -> ColoredString

Colour the block String
Source§

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

Formats the value associated with the block into a display 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 example_blocks() -> Vec<Self>
where Self: Sized,

Example blocks for generated files
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 Bus

Source§

fn clone(&self) -> Bus

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 Bus

Source§

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

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

impl Default for Bus

Source§

fn default() -> Bus

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

impl<'de> Deserialize<'de> for Bus

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 Bus

Source§

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

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

impl From<&BusInfo> for Bus

Source§

fn from(bus: &BusInfo) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Bus

A generic Bus from a u8 bus number - used if Bus profiling is not available

Source§

fn from(bus: u8) -> Self

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Bus

Source§

type Item = &'a Device

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<&'a Bus 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 Serialize for Bus

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§

§

impl Freeze for Bus

§

impl RefUnwindSafe for Bus

§

impl Send for Bus

§

impl Sync for Bus

§

impl Unpin for Bus

§

impl UnsafeUnpin for Bus

§

impl UnwindSafe for Bus

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>,