|
|
|
@ -2,20 +2,28 @@
|
|
|
|
|
|
|
|
|
|
### Instructions |
|
|
|
|
|
|
|
|
|
Write a function that tries to open a file and panics if the file |
|
|
|
|
doesn't exist |
|
|
|
|
Write a **function** that tries to open a file and panics if the file |
|
|
|
|
does not exist. |
|
|
|
|
|
|
|
|
|
### Notions |
|
|
|
|
|
|
|
|
|
### Expected Function |
|
|
|
|
|
|
|
|
|
```rust |
|
|
|
|
pub fn open_file(s: &str) -> File {} |
|
|
|
|
pub fn open_file(s: &str) -> File { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
### Usage |
|
|
|
|
|
|
|
|
|
Here is a program to test your function |
|
|
|
|
Here is a program to test your function: |
|
|
|
|
|
|
|
|
|
```rust |
|
|
|
|
use std::fs::File; |
|
|
|
|
use std::fs; |
|
|
|
|
use panic::*; |
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
|
let filename = "created.txt"; |
|
|
|
|
File::create(filename).unwrap(); |
|
|
|
|