Skip to main content

SysClass

Trait SysClass 

Source
pub trait SysClass: Sized {
Show 14 methods // Required methods fn class() -> &'static str; unsafe fn from_path_unchecked(path: PathBuf) -> Self; fn path(&self) -> &Path; // Provided methods fn base() -> &'static str { ... } fn dir() -> PathBuf { ... } fn from_path(path: &Path) -> Result<Self> { ... } fn all() -> Result<Vec<Self>> { ... } fn iter() -> Box<dyn Iterator<Item = Result<Self>>> where Self: 'static { ... } fn new(id: &str) -> Result<Self> { ... } fn id(&self) -> &str { ... } fn read_file<P: AsRef<Path>>(&self, name: P) -> Result<String> { ... } fn parse_file<F: FromStr, P: AsRef<Path>>(&self, name: P) -> Result<F> where F::Err: Display { ... } fn trim_file<P: AsRef<Path>>(&self, name: P) -> Result<String> { ... } fn write_file<P: AsRef<Path>, S: AsRef<[u8]>>( &self, name: P, data: S, ) -> Result<()> { ... }
}

Required Methods§

Source

fn class() -> &'static str

Return the class of the sys object, the name of a folder in `/sys/${base}``

Source

unsafe fn from_path_unchecked(path: PathBuf) -> Self

Create a sys object from an absolute path without checking path for validity

Source

fn path(&self) -> &Path

Return the path of the sys object

Provided Methods§

Source

fn base() -> &'static str

Sets the base directory, which defaults to class.

Source

fn dir() -> PathBuf

Return the path to the sys objects, the full path of a folder in /sys/class

Source

fn from_path(path: &Path) -> Result<Self>

Create a sys object from a path, checking it for validity

Source

fn all() -> Result<Vec<Self>>

Retrieve all of the object instances of a sys class

Examples found in repository?
examples/scsi_host.rs (line 5)
4fn main() -> io::Result<()> {
5    for host in ScsiHost::all()? {
6        println!(
7            "{} has power management policy \"{:?}\"",
8            host.id(),
9            host.link_power_management_policy()
10        );
11    }
12
13    Ok(())
14}
More examples
Hide additional examples
examples/pci.rs (line 5)
4fn main() -> io::Result<()> {
5    for dev in PciDevice::all()? {
6        println!("PCI Device: {}", dev.id());
7    }
8
9    for dev in PciDriver::iter() {
10        let dev = dev?;
11        println!("PCI Driver: {}", dev.id());
12    }
13
14    Ok(())
15}
examples/leds.rs (line 5)
4fn main() -> io::Result<()> {
5    for dev in Leds::all()? {
6        println!(
7            "{} brightness: {} / {}",
8            dev.id(),
9            dev.brightness().unwrap(),
10            dev.max_brightness().unwrap()
11        );
12    }
13
14    Ok(())
15}
examples/backlight.rs (line 5)
4fn main() -> io::Result<()> {
5    for dev in Backlight::all()? {
6        println!(
7            "{} brightness: {} / {}",
8            dev.id(),
9            dev.brightness().unwrap(),
10            dev.max_brightness().unwrap()
11        );
12    }
13
14    Ok(())
15}
examples/block.rs (line 5)
4fn main() -> io::Result<()> {
5    for block in Block::all()? {
6        if block.has_device() {
7            println!("Path: {:?}", block.path());
8            println!("  Model: {:?}", block.device_model());
9            println!("  Vendor: {:?}", block.device_vendor());
10            println!("  Rev: {:?}", block.device_rev());
11            println!("  Children: {:#?}", block.children());
12        }
13    }
14
15    Ok(())
16}
Source

fn iter() -> Box<dyn Iterator<Item = Result<Self>>>
where Self: 'static,

Retrieve all of the object instances of a sys class, with a boxed iterator

Examples found in repository?
examples/pci.rs (line 9)
4fn main() -> io::Result<()> {
5    for dev in PciDevice::all()? {
6        println!("PCI Device: {}", dev.id());
7    }
8
9    for dev in PciDriver::iter() {
10        let dev = dev?;
11        println!("PCI Driver: {}", dev.id());
12    }
13
14    Ok(())
15}
More examples
Hide additional examples
examples/net.rs (line 5)
4fn main() -> io::Result<()> {
5    for dev in Net::iter() {
6        let dev = dev?;
7
8        println!("{}: {}", dev.id(), dev.address().unwrap());
9        println!("    MTU: {}", dev.mtu().unwrap());
10        println!("    Duplex: {:?}", dev.duplex());
11
12        let statistics = dev.statistics();
13        println!(
14            "    RX: {} MiB",
15            statistics.rx_bytes().unwrap() / (1024 * 1024)
16        );
17        println!(
18            "    TX: {} MiB",
19            statistics.tx_bytes().unwrap() / (1024 * 1024)
20        );
21    }
22
23    Ok(())
24}
Source

fn new(id: &str) -> Result<Self>

Create a sys object by id, checking it for validity

Source

fn id(&self) -> &str

Return the id of the sys object

Examples found in repository?
examples/scsi_host.rs (line 8)
4fn main() -> io::Result<()> {
5    for host in ScsiHost::all()? {
6        println!(
7            "{} has power management policy \"{:?}\"",
8            host.id(),
9            host.link_power_management_policy()
10        );
11    }
12
13    Ok(())
14}
More examples
Hide additional examples
examples/pci.rs (line 6)
4fn main() -> io::Result<()> {
5    for dev in PciDevice::all()? {
6        println!("PCI Device: {}", dev.id());
7    }
8
9    for dev in PciDriver::iter() {
10        let dev = dev?;
11        println!("PCI Driver: {}", dev.id());
12    }
13
14    Ok(())
15}
examples/leds.rs (line 8)
4fn main() -> io::Result<()> {
5    for dev in Leds::all()? {
6        println!(
7            "{} brightness: {} / {}",
8            dev.id(),
9            dev.brightness().unwrap(),
10            dev.max_brightness().unwrap()
11        );
12    }
13
14    Ok(())
15}
examples/backlight.rs (line 8)
4fn main() -> io::Result<()> {
5    for dev in Backlight::all()? {
6        println!(
7            "{} brightness: {} / {}",
8            dev.id(),
9            dev.brightness().unwrap(),
10            dev.max_brightness().unwrap()
11        );
12    }
13
14    Ok(())
15}
examples/net.rs (line 8)
4fn main() -> io::Result<()> {
5    for dev in Net::iter() {
6        let dev = dev?;
7
8        println!("{}: {}", dev.id(), dev.address().unwrap());
9        println!("    MTU: {}", dev.mtu().unwrap());
10        println!("    Duplex: {:?}", dev.duplex());
11
12        let statistics = dev.statistics();
13        println!(
14            "    RX: {} MiB",
15            statistics.rx_bytes().unwrap() / (1024 * 1024)
16        );
17        println!(
18            "    TX: {} MiB",
19            statistics.tx_bytes().unwrap() / (1024 * 1024)
20        );
21    }
22
23    Ok(())
24}
Source

fn read_file<P: AsRef<Path>>(&self, name: P) -> Result<String>

Read a file underneath the sys object

Source

fn parse_file<F: FromStr, P: AsRef<Path>>(&self, name: P) -> Result<F>
where F::Err: Display,

Parse a number from a file underneath the sys object

Source

fn trim_file<P: AsRef<Path>>(&self, name: P) -> Result<String>

Read a file underneath the sys object and trim whitespace

Source

fn write_file<P: AsRef<Path>, S: AsRef<[u8]>>( &self, name: P, data: S, ) -> Result<()>

Write a file underneath the sys object

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§