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§
Sourcefn class() -> &'static str
fn class() -> &'static str
Return the class of the sys object, the name of a folder in `/sys/${base}``
Sourceunsafe fn from_path_unchecked(path: PathBuf) -> Self
unsafe fn from_path_unchecked(path: PathBuf) -> Self
Create a sys object from an absolute path without checking path for validity
Provided Methods§
Sourcefn dir() -> PathBuf
fn dir() -> PathBuf
Return the path to the sys objects, the full path of a folder in /sys/class
Sourcefn from_path(path: &Path) -> Result<Self>
fn from_path(path: &Path) -> Result<Self>
Create a sys object from a path, checking it for validity
Sourcefn all() -> Result<Vec<Self>>
fn all() -> Result<Vec<Self>>
Retrieve all of the object instances of a sys class
Examples found in repository?
More 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}Sourcefn iter() -> Box<dyn Iterator<Item = Result<Self>>>where
Self: 'static,
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
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}Sourcefn id(&self) -> &str
fn id(&self) -> &str
Return the id of the sys object
Examples found in repository?
More 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}Sourcefn read_file<P: AsRef<Path>>(&self, name: P) -> Result<String>
fn read_file<P: AsRef<Path>>(&self, name: P) -> Result<String>
Read a file underneath the sys object
Sourcefn parse_file<F: FromStr, P: AsRef<Path>>(&self, name: P) -> Result<F>
fn parse_file<F: FromStr, P: AsRef<Path>>(&self, name: P) -> Result<F>
Parse a number from 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".