wrong number of type arguments: expected 2, found 1
expected 2 type argumentsrustc(E0107)
lib.rs(21, 37): expected 2 type arguments
...which I assume means I need to return a Result with an Error as well. This makes sense as an io operation likely could result in an error.
If I return Result<String, Error> and import Error like this:
use std::error::Error;
, I get:
the size for values of type `(dyn std::error::Error + 'static)` cannot be known at compilation time
doesn't have a size known at compile-time
help: the trait `std::marker::Sized` is not implemented for `(dyn std::error::Error + 'static)`rustc(E0277)
If that's the case, what's up with the docs on read_to_string? I would assume the docs would be clear about its return type and thus I could use the same return type in the calling function above.
Clearly I'm missing something and glad in advance to be taught...
In the future, please put error messages in code blocks. That makes them much easier to read.
The problem here is that std::error::Error is a trait, and traits are not types, and their values cannot exist on their own. To exist as a value, a trait must be behind a reference or smart pointer (often a Box).
Anyway, you are probably looking for std::io::Error here, which is not a trait, but an actual type.
Yes, but if you check what is this Result, you'll see that it's not the ordinary Result, but std::io::Result. Just return it explicitly, and all should be good.
Rust has std::result::Result and std::io::Result, which unfortunately are two different types.
Same with std::error::Errorinterface (trait) and std::io::Errortype.
In this case I think rustdoc is just not presenting it clearly enough. It should be showing io::Result IMHO.
The std::error::Error isn't a thing that can be returned, because it's only a trait, an interface that describes how to implement actual types, but by itself it has no data.
Because returning a trait wouldn't make sense, Rust interprets your trait syntax as dyn Error, which unfortunately also doesn't make sense here either. You'd need either Box<dyn error::Error> or io::Error>.