Kai Sellgren
Kai Sellgren

Reputation: 30202

Why can I call File::open(...).read_to_end()?

The following code works and I don't know why:

File::open(&some_path).read_to_end().unwrap();

Looking at the API docs I can see File::open() returning a IoResult which does not have a read_to_end().

Is there some kind of syntax sugar going on? Does Result<T, Error> somehow turn into Result<U, Error>?

Documentation: http://doc.rust-lang.org/std/io/fs/struct.File.html#method.read_to_end

Upvotes: 7

Views: 564

Answers (1)

Arjan
Arjan

Reputation: 21465

read_to_end is from the Reader trait and if you look there you can see that there is an implementation for reader for IoResult<R> for any R that implements Reader:

impl<R: Reader> Reader for IoResult<R>

Upvotes: 5

Related Questions