fn parse_size(arg: &str) -> Result<u64> {
    let arg = arg.trim();
    // Index of first non digit, or arg len.
    let idx = arg
        .find(|c: char| !c.is_ascii_digit())
        .unwrap_or_else(|| arg.len());
    let num: u64 = arg[..idx].trim().parse()?;
    let suf = arg[idx..].trim().to_ascii_uppercase();

    match &*suf {
        "" => Ok(num),
        "K" => Ok(Size::from_kib(num).as_bytes()),
        "M" => Ok(Size::from_mib(num).as_bytes()),
        "G" => Ok(Size::from_gib(num).as_bytes()),
        "T" => Ok(Size::from_tib(num).as_bytes()),
        _ => Err(anyhow!("Invalid suffix")),
    }
}
// TODO: Have parts::types::Size impl FromStr and use that instead.
Have parts::types::Size impl FromStr and use that instead.
Have parts :: types :: Size impl FromStr and use that instead .
fn parse_size(arg: &str) -> Result<u64> {
    let arg = arg.trim();
    // Index of first non digit, or arg len.
    let idx = arg
        .find(|c: char| !c.is_ascii_digit())
        .unwrap_or_else(|| arg.len());
    let num: u64 = arg[..idx].trim().parse()?;
    let suf = arg[idx..].trim().to_ascii_uppercase();
    match &*suf {
        "" => Ok(num),
        "K" => Ok(Size::from_kib(num).as_bytes()),
        "M" => Ok(Size::from_mib(num).as_bytes()),
        "G" => Ok(Size::from_gib(num).as_bytes()),
        "T" => Ok(Size::from_tib(num).as_bytes()),
        _ => Err(anyhow!("Invalid suffix")),
    }
}
fn parse_size ( arg : & str ) -> Result < u64 > { let arg = arg . trim ( ) ; // Index of first non digit, or arg len. let idx = arg . find ( | c : char | ! c . is_ascii_digit ( ) ) . unwrap_or_else ( | | arg . len ( ) ) ; let num : u64 = arg [ .. idx ] . trim ( ) . parse ( ) ? ; let suf = arg [ idx .. ] . trim ( ) . to_ascii_uppercase ( ) ; match & * suf { " " => Ok ( num ) , " " => Ok ( Size :: from_kib ( num ) . as_bytes ( ) ) , " " => Ok ( Size :: from_mib ( num ) . as_bytes ( ) ) , " " => Ok ( Size :: from_gib ( num ) . as_bytes ( ) ) , " " => Ok ( Size :: from_tib ( num ) . as_bytes ( ) ) , _ => Err ( anyhow ! ( " " ) ) , } }
TODO: Have parts::types::Size impl FromStr and use that instead.
TODO : Have parts :: types :: Size impl FromStr and use that instead .
arg
&str
arg
&str