Function sysctl::value_oid_as [] [src]

pub fn value_oid_as<T>(oid: &Vec<i32>) -> Result<Box<T>, String>

A generic function that takes an OID as argument and returns a result containing the sysctl value if success, the errno caused by sysctl() as string if failure.

Can 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 */
}

#[cfg(not(target_os = "macos"))]
fn main() {
    let oid = vec![libc::CTL_KERN, libc::KERN_CLOCKRATE];
    println!("{:?}", sysctl::value_oid_as::<ClockInfo>(&oid));
}
#[cfg(target_os = "macos")]
fn main() {
    let mut oid = vec![libc::CTL_KERN, libc::KERN_CLOCKRATE];
    println!("{:?}", sysctl::value_oid_as::<ClockInfo>(&mut oid));
}