Mercurial > lbo > hg > myi3stat
changeset 11:c2dc7a85a0e3
Handle file read errors in helper
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 14 Feb 2016 14:48:00 +0100 |
parents | ab47007c73a9 |
children | 79ca03c87498 |
files | src/helper.rs |
diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/helper.rs Sun Feb 14 12:54:20 2016 +0100 +++ b/src/helper.rs Sun Feb 14 14:48:00 2016 +0100 @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use std::fs; use std::io::Read; @@ -23,9 +25,10 @@ } let mut buf = String::with_capacity(size); - file.read_to_string(&mut buf); - - Some(buf) + match file.read_to_string(&mut buf) { + Err(_) => None, + Ok(_) => Some(buf), + } } pub fn get_procfs_file_lines(path: String) -> Option<Vec<String>> {