Struct Devices

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

Information about system devices.

Implementations§

Source§

impl Devices

Source

pub fn get() -> Result<Vec<DeviceInfo>, Error>

Retrieve a list of all connected devices.

§Errors

If the platform is unsupported or there is an issue retrieving the list of devices, an error is returned.

Examples found in repository?
examples/main.rs (line 5)
3fn main() {
4    // Return all connected devices
5    match Devices::get() {
6        Ok(devices) => {
7            for device in devices {
8                println!("{:?}", device);
9            }
10        }
11        Err(e) => {
12            println!("Devices::get() returned Error {:?}", e);
13        }
14    }
15
16    // Return only PCI devices
17    match Devices::pci() {
18        Ok(devices) => {
19            for device in devices {
20                println!("{:?}", device);
21            }
22        }
23        Err(e) => {
24            println!("Devices::get() returned Error {:?}", e);
25        }
26    }
27
28    // Return only USB devices
29    match Devices::usb() {
30        Ok(devices) => {
31            for device in devices {
32                println!("{:?}", device);
33            }
34        }
35        Err(e) => {
36            println!("Devices::get() returned Error {:?}", e);
37        }
38    }
39}
Source

pub fn pci() -> Result<Vec<DeviceInfo>, Error>

Retrieve a list of all connected PCI devices.

§Errors

If the platform is unsupported or there is an issue retrieving the list of devices, an error is returned.

Examples found in repository?
examples/main.rs (line 17)
3fn main() {
4    // Return all connected devices
5    match Devices::get() {
6        Ok(devices) => {
7            for device in devices {
8                println!("{:?}", device);
9            }
10        }
11        Err(e) => {
12            println!("Devices::get() returned Error {:?}", e);
13        }
14    }
15
16    // Return only PCI devices
17    match Devices::pci() {
18        Ok(devices) => {
19            for device in devices {
20                println!("{:?}", device);
21            }
22        }
23        Err(e) => {
24            println!("Devices::get() returned Error {:?}", e);
25        }
26    }
27
28    // Return only USB devices
29    match Devices::usb() {
30        Ok(devices) => {
31            for device in devices {
32                println!("{:?}", device);
33            }
34        }
35        Err(e) => {
36            println!("Devices::get() returned Error {:?}", e);
37        }
38    }
39}
Source

pub fn usb() -> Result<Vec<DeviceInfo>, Error>

Retrieve a list of all connected USB devices.

§Errors

If the platform is unsupported or there is an issue retrieving the list of devices, an error is returned.

Examples found in repository?
examples/main.rs (line 29)
3fn main() {
4    // Return all connected devices
5    match Devices::get() {
6        Ok(devices) => {
7            for device in devices {
8                println!("{:?}", device);
9            }
10        }
11        Err(e) => {
12            println!("Devices::get() returned Error {:?}", e);
13        }
14    }
15
16    // Return only PCI devices
17    match Devices::pci() {
18        Ok(devices) => {
19            for device in devices {
20                println!("{:?}", device);
21            }
22        }
23        Err(e) => {
24            println!("Devices::get() returned Error {:?}", e);
25        }
26    }
27
28    // Return only USB devices
29    match Devices::usb() {
30        Ok(devices) => {
31            for device in devices {
32                println!("{:?}", device);
33            }
34        }
35        Err(e) => {
36            println!("Devices::get() returned Error {:?}", e);
37        }
38    }
39}

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.