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 see File::open() returning an IoResult that does not have read_to_end() .

Is there any syntactic sugar? Can Result<T, Error> turn into Result<U, Error> ?

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

+8
rust
source share
1 answer

read_to_end refers to the Reader read_to_end , and if you look there, you will see that there is a read implementation for IoResult<R> for any R that implements Reader :

 impl<R: Reader> Reader for IoResult<R> 
+6
source share

All Articles