mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
601 B
35 lines
601 B
4 years ago
|
## panic
|
||
|
|
||
|
### Instructions
|
||
|
|
||
|
Write a function that tries to open a file and panics if the file
|
||
|
doesn't exist
|
||
|
|
||
|
### Expected Function
|
||
|
|
||
|
```rust
|
||
|
pub fn open_file(s: &str) -> File {}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
|
Here is a program to test your function
|
||
|
|
||
|
```rust
|
||
|
fn main() {
|
||
|
let filename = "created.txt";
|
||
|
File::create(filename).unwrap();
|
||
|
let a = open_file(filename);
|
||
|
println!("{:?}", a);
|
||
|
fs::remove_file(filename).unwrap();
|
||
|
}
|
||
|
```
|
||
|
|
||
|
And its output:
|
||
|
|
||
|
```console
|
||
|
student@ubuntu:~/[[ROOT]]/test$ cargo run
|
||
|
File { fd: 3, path: "[[ROOT]]/a.txt", read: true, write: false }
|
||
|
student@ubuntu:~/[[ROOT]]/test$
|
||
|
```
|