Paul Razvan Berg
Paul Razvan Berg

Reputation: 21400

What does Result<()> without the error type mean?

I was looking at the std::env::current_dir documentation and this caught my attention:

std::io::Result<()>

I thought a Result should have a T and an E. How can you substitute them with ()?

Upvotes: 8

Views: 2041

Answers (1)

Brian61354270
Brian61354270

Reputation: 14423

std::io::Result is a type alias specific to the std::io module, which is defined as

type Result<T> = Result<T, ::std::io::Error>;

Essentially, it's a std::result::Result with the error type prefilled as a std::io::Error. Using this type only requires one type parameter, which corresponds to the "ok" type T in Result<T,E>.

Upvotes: 10

Related Questions