-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fredrik Klingenberg <[email protected]>
- Loading branch information
Showing
1 changed file
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
use std::fs::File; | ||
use std::io::{self, ErrorKind}; | ||
use std::io::Read; | ||
|
||
fn main() { | ||
let greeting_file_result = File::open("hello.txt"); | ||
let _greeting_file = match greeting_file_result { | ||
Ok(file) => file, | ||
Err(error) => panic!("Problem opening the file: {:?}", error), | ||
Err(error) => match error.kind() { | ||
ErrorKind::NotFound => match File::create("hello.txt") { | ||
Ok(fc) => fc, | ||
Err(e) => { | ||
panic!("Problem creating the file: {:?}", e) | ||
}, | ||
}, | ||
other_error => { | ||
panic!("Problem opening the file: {:?}", other_error) | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
fn read_username_from_file() -> Result<String, io::Error> { | ||
let mut username_file = File::open("hello.txt")?; | ||
let mut username = String::new(); | ||
username_file.read_to_string(&mut username)?; | ||
Ok(username) | ||
} |