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

1

7

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

Kneeland answered 8/3, 2020 at 15:5 Comment(3)
That's a std::io::Result, not a std::result::Result.Jesusa
Does this answer your question? Result getting unexpected type argumentTeach
Thanks @SCappella, both your link and Brian's answer are helpful.Kneeland
J
9

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

Jesusa answered 8/3, 2020 at 15:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.