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

1.3k Views Asked by At

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 ()?

1

There are 1 best solutions below

0
On BEST ANSWER

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>.