~deadjakk/RiceStats

6c0ba822ec03e8a30d70ebca0b433dba42faf22f — deadjakk 2 years ago eb70637
changed usage formatting to float
1 files changed, 6 insertions(+), 6 deletions(-)

M src/network.rs
M src/network.rs => src/network.rs +6 -6
@@ 26,16 26,16 @@ pub fn usage(output_line: &mut String, provided_interface: Option<String>) -> Re
    let first =  get_traffic(&int_path,true)?;
    sleep(Duration::from_millis(1000));
    let second = get_traffic(&int_path,true)?;
    let tx = second-first;
    let tx = (second-first)/1000.0;
    let first =  get_traffic(&int_path,false)?;
    sleep(Duration::from_millis(1000));
    let second = get_traffic(&int_path,false)?;
    let rx = second-first;
    output_line.push_str(&format!("rx-{} tx-{} ",rx,tx));
    let rx = (second-first)/1000.0;
    output_line.push_str(&format!("rx-{:.1}kb/s tx-{:.1}kb/s ",rx,tx));
    return Ok(());
}

fn get_traffic(path: &PathBuf,tx: bool) -> Result<usize,Box<dyn Error>> {
fn get_traffic(path: &PathBuf,tx: bool) -> Result<f32,Box<dyn Error>> {
    let mut f_path = PathBuf::new();
    f_path.push("/sys/class/net/");
    f_path.push(path);


@@ 49,7 49,7 @@ fn get_traffic(path: &PathBuf,tx: bool) -> Result<usize,Box<dyn Error>> {
    let contents = read(f_path)?;
    let mut contents = from_utf8(&contents)?.to_string();
    contents.truncate(contents.len()-1);
    let contents_parsed = contents.parse::<usize>()?;
    let contents_parsed = contents.parse::<f32>()?;
    Ok(contents_parsed)
}



@@ 70,7 70,7 @@ fn find_interface() -> Result<OsString,Box<dyn Error>> {
        .map(|res| res.map(|e| e.path()))
        .collect::<Result<Vec<_>, std::io::Error>>()?;

    let mut max = 0;
    let mut max = 0.0;
    let mut primary = OsString::from("_");
    for int in ints {
        let name = int.file_name().unwrap();