fn from_str(meminfo: &str) -> Result<Self> {
        enum Currently {
            Total,
            Free,
            Available,
            Cached,
            Unknown,
            None,
        };

        let mut word = String::new();
        let mut info = MemInfo {
            total: None,
            free: None,
            available: None,
            cached: None,
        };
        let mut amount: usize;
        let mut currently = Currently::None;

        for chr in meminfo.chars() {
            match chr {
                c if 'A' <= c && c <= 'z' => {
                    word.push(chr);
                }
                ':' => {
                    match &word[..] {
                        "MemTotal" => currently = Currently::Total,
                        "MemAvailable" => currently = Currently::Available,
                        "MemFree" => currently = Currently::Free,
                        "Cached" => currently = Currently::Cached,
                        _ => currently = Currently::Unknown,
                    }
                    word.clear();
                }
                x if '0' <= x && x <= '9' => {
                    word.push(chr);
                }
                ' ' | '\n' => {
                    if word.is_empty() {
                        continue;
                    }
                    if word == "kB" {
                        word.clear();
                        continue;
                    }

                    amount = match word.parse() {
                        Ok(amount) => amount,
                        Err(e) => panic!(r#"Unable to parse number from "{}": {:?}"#, word, e),
                    };
                    word.clear();

                    match currently {
                        Currently::Total => info.total = Some(amount),
                        Currently::Free => info.free = Some(amount),
                        Currently::Available => info.available = Some(amount),
                        Currently::Cached => info.cached = Some(amount),
                        Currently::Unknown => {
                            // don't care
                        }
                        Currently::None => panic!(
                            "Unexpectedly parsed a number before figuring out where I am: \
                             {}",
                            amount
                        ),
                    }
                }
                _ => {
                    // Don't care about other chars
                }
            }
        }

        Ok(info)
    }
/// Convert the contents of a string like /proc/meminfo into a MemInfo
/// object
Convert the contents of a string like /proc/meminfo into a MemInfo
object
Convert the contents of a string like / proc / meminfo into a MemInfo object
fn from_str(meminfo: &str) -> Result<Self> {
        enum Currently {
            Total,
            Free,
            Available,
            Cached,
            Unknown,
            None,
        };
        let mut word = String::new();
        let mut info = MemInfo {
            total: None,
            free: None,
            available: None,
            cached: None,
        };
        let mut amount: usize;
        let mut currently = Currently::None;
        for chr in meminfo.chars() {
            match chr {
                c if 'A' <= c && c <= 'z' => {
                    word.push(chr);
                }
                ':' => {
                    match &word[..] {
                        "MemTotal" => currently = Currently::Total,
                        "MemAvailable" => currently = Currently::Available,
                        "MemFree" => currently = Currently::Free,
                        "Cached" => currently = Currently::Cached,
                        _ => currently = Currently::Unknown,
                    }
                    word.clear();
                }
                x if '0' <= x && x <= '9' => {
                    word.push(chr);
                }
                ' ' | '\n' => {
                    if word.is_empty() {
                        continue;
                    }
                    if word == "kB" {
                        word.clear();
                        continue;
                    }
                    amount = match word.parse() {
                        Ok(amount) => amount,
                        Err(e) => panic!(r#"Unable to parse number from "{}": {:?}"#, word, e),
                    };
                    word.clear();
                    match currently {
                        Currently::Total => info.total = Some(amount),
                        Currently::Free => info.free = Some(amount),
                        Currently::Available => info.available = Some(amount),
                        Currently::Cached => info.cached = Some(amount),
                        Currently::Unknown => {
                            // don't care
                        }
                        Currently::None => panic!(
                            "Unexpectedly parsed a number before figuring out where I am: \
                             {}",
                            amount
                        ),
                    }
                }
                _ => {
                    // Don't care about other chars
                }
            }
        }
        Ok(info)
    }
fn from_str ( meminfo : & str ) -> Result < Self > { enum Currently { Total , Free , Available , Cached , Unknown , None , } ; let mut word = String :: new ( ) ; let mut info = MemInfo { total : None , free : None , available : None , cached : None , } ; let mut amount : usize ; let mut currently = Currently :: None ; for chr in meminfo . chars ( ) { match chr { c if 'A' <= c && c <= 'z' => { word . push ( chr ) ; } ':' => { match & word [ .. ] { " " => currently = Currently :: Total , " " => currently = Currently :: Available , " " => currently = Currently :: Free , " " => currently = Currently :: Cached , _ => currently = Currently :: Unknown , } word . clear ( ) ; } x if '0' <= x && x <= '9' => { word . push ( chr ) ; } ' ' | '\n' => { if word . is_empty ( ) { continue ; } if word == " " { word . clear ( ) ; continue ; } amount = match word . parse ( ) { Ok ( amount ) => amount , Err ( e ) => panic ! ( r#"Unable to parse number from "{}": {:?}"# word e ) , } ; word . clear ( ) ; match currently { Currently :: Total => info . total = Some ( amount ) , Currently :: Free => info . free = Some ( amount ) , Currently :: Available => info . available = Some ( amount ) , Currently :: Cached => info . cached = Some ( amount ) , Currently :: Unknown => { // don't care } Currently :: None => panic ! ( " \
 " amount ) , } } _ => { // Don't care about other chars } } } Ok ( info ) }
Convert the contents of a string like /proc/meminfo into a MemInfo
object
Convert the contents of a string like / proc / meminfo into a MemInfo object
meminfo
&str
meminfo
&str