Why am I getting “unused Result which must be used … Result may be an Err variant, which should be handled” even though I am handling it?

You’re not handling the result, you’re mapping the result from one type to another. foo().map_err(|err| println!(“{:?}”, err)); What that line does is call foo(), which returns Result<(), std::io::Error>. Then map_err uses the type returned by your closure (in this case, ()), and modifies the error type and returns Result<(), ()>. This is the result that …

Read more

How to restrict the construction of struct?

Answer to question You cannot create that struct from member initialization, because members are by default private and cannot be used directly. Only the immediate module and its submodules can access private fields, functions, … (see the book about visibility). Your example works, because your function is in that certain scope. mod foo { pub …

Read more