This section of the program writes to a .txt file, but i get that error.
-snip-
let mut world_file = File::create(layer_path);
world_file.write_all("testing".as_bytes()).expect("Uh Oh....");
-snip-
This section of the program writes to a .txt file, but i get that error.
-snip-
let mut world_file = File::create(layer_path);
world_file.write_all("testing".as_bytes()).expect("Uh Oh....");
-snip-
File::create
returns a Result
as it may fail. You will have to either handle the possible error, propagate it out of the current function using the ?
operator, or panic on errors using .expect("failed to create file")
.
I did use .expect though, do i need to use the ? operator?
You used .expect on the write_all call, but not on the File::create call.
I put .expect on the end of the create file function, but:
error[E0061]: this function takes 1 argument but 0 arguments were supplied
--> src/main.rs:101:63
|
101 | let mut world_file = File::create(layer_path).expect();
| ^^^^^^- supplied 0 arguments
| |
| expected 1 argument
|
note: associated function defined here
.expect
requires a string argument. Try let mut world_file = File::create(layer_path).expect("failed to create file");
Ok, Fixed it!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.