Struct sysctl::Ctl
[−]
[src]
pub struct Ctl { /* fields omitted */ }This struct represents a system control.
Methods
impl Ctl[src]
pub fn new(name: &str) -> Result<Self, SysctlError>[src]
Construct a Ctl from the name.
This is just a wrapper around Ctl::from_str.
Example
extern crate sysctl; use sysctl::Ctl; let ctl = Ctl::new("kern.osrelease");
pub fn name(&self) -> Result<String, SysctlError>[src]
Returns a result containing the sysctl name on success, or a SysctlError on failure.
Example
extern crate sysctl; use sysctl::Ctl; let ctl = Ctl::new("kern.osrelease").expect("could not get sysctl"); assert_eq!(ctl.name().expect("could not get name"), "kern.osrelease");
pub fn value_type(&self) -> Result<CtlType, SysctlError>[src]
Returns a result containing the sysctl value type on success, or a Sysctl Error on failure.
Example
extern crate sysctl; use sysctl::{Ctl, CtlType}; let osrelease = Ctl::new("kern.osrelease") .expect("Could not get kern.osrelease sysctl"); let value_type = osrelease.value_type() .expect("Could notget kern.osrelease value type"); assert_eq!(value_type, CtlType::String);
pub fn description(&self) -> Result<String, SysctlError>[src]
Returns a result containing the sysctl description if success, or an Error on failure.
Example
extern crate sysctl; use sysctl::Ctl; fn main() { let osrevision = sysctl::Ctl::new("kern.osrevision") .expect("could not get kern.osrevision sysctl"); println!("Description: {:?}", osrevision.description()) }
pub fn value(&self) -> Result<CtlValue, SysctlError>[src]
Returns a result containing the sysctl value on success, or a SysctlError on failure.
Example
extern crate sysctl; extern crate libc; fn main() { let osrevision = sysctl::Ctl::new("kern.osrevision") .expect("could not get kern.osrevisio sysctl"); println!("Value: {:?}", osrevision.value()); }
pub fn value_as<T>(&self) -> Result<Box<T>, SysctlError>[src]
A generic method that takes returns a result containing the sysctl value if success, or a SysctlError on failure.
May only be called for sysctls of type Opaque or Struct.
Example
extern crate sysctl; extern crate libc; use libc::c_int; #[derive(Debug)] #[repr(C)] struct ClockInfo { hz: c_int, /* clock frequency */ tick: c_int, /* micro-seconds per hz tick */ spare: c_int, stathz: c_int, /* statistics clock frequency */ profhz: c_int, /* profiling clock frequency */ } fn main() { let clockrate = sysctl::Ctl::new("kern.clockrate") .expect("could not get clockrate sysctl"); println!("{:?}", clockrate.value_as::<ClockInfo>()); }
pub fn set_value(&self, value: CtlValue) -> Result<CtlValue, SysctlError>[src]
Sets the value of a sysctl. Fetches and returns the new value if successful, or returns a SysctlError on failure.
Example
extern crate sysctl; use sysctl::Ctl; fn main() { let usbdebug = Ctl::new("hw.usb.debug") .expect("could not get hw.usb.debug control"); let original = usbdebug.value() .expect("could not get value"); let set = usbdebug.set_value(sysctl::CtlValue::Int(0)); println!("hw.usb.debug: {:?} -> {:?}", original, set); let set = usbdebug.set_value(sysctl::CtlValue::Int(1)); println!("hw.usb.debug: 0 -> {:?}", set); let reset = usbdebug.set_value(original); println!("hw.usb.debug: 1 -> {:?}", reset); }
pub fn flags(&self) -> Result<CtlFlags, SysctlError>[src]
Get the flags for a sysctl.
Returns a Result containing the flags on success, or a SysctlError on failure.
Example
extern crate sysctl; use sysctl::{Ctl, CtlFlags}; fn main() { let osrev = Ctl::new("kern.osrevision") .expect("could not get control"); let readable = osrev.flags() .expect("could not get flags") .contains(CtlFlags::RD); assert!(readable); }
Trait Implementations
impl Debug for Ctl[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more
impl Clone for Ctl[src]
fn clone(&self) -> Ctl[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl PartialEq for Ctl[src]
fn eq(&self, __arg_0: &Ctl) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Ctl) -> bool[src]
This method tests for !=.
impl FromStr for Ctl[src]
type Err = SysctlError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>[src]
Parses a string s to return a value of this type. Read more
impl IntoIterator for Ctl[src]
Ctl implements the IntoIterator trait to allow for easy iteration over nodes.
Example
extern crate sysctl; use sysctl::Ctl; let kern = Ctl::new("kern"); for ctl in kern { let name = ctl.name().expect("could not get name"); println!("{}", name); }