fixed file write

This commit is contained in:
Simon Wörner
2017-03-30 21:55:12 +02:00
parent 80934a5c70
commit 70e994eef9

View File

@@ -40,20 +40,17 @@ static GPIO_BTN_ON: &'static str = "0";
static GPIO_LED_ON: &'static str = "0"; static GPIO_LED_ON: &'static str = "0";
static GPIO_LED_OFF: &'static str = "1"; static GPIO_LED_OFF: &'static str = "1";
fn open(path: &str) -> File {
return File::open(Path::new(path))
.expect(format!("Open file '{}' failed", path).as_str());
}
fn write(path: &str, value: &str) { fn write(path: &str, value: &str) {
let mut file = open(path); let mut file = File::create(Path::new(path))
.expect(format!("Open file '{}' failed", path).as_str());
file.write_all(value.as_bytes()) file.write_all(value.as_bytes())
.expect(format!("Write value '{}' to '{}' file failed", value, path).as_str()); .expect(format!("Write value '{}' to '{}' file failed", value, path).as_str());
} }
fn read(path: &str) -> String { fn read(path: &str) -> String {
let mut file = open(path); let mut file = File::open(Path::new(path))
.expect(format!("Open file '{}' failed", path).as_str());
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents) file.read_to_string(&mut contents)