问题
If I define a function:
fn f() -> Result<(), E> {
// How to return Ok()?
}
How can I return the Ok
in std::result
with the unit type ()
?
回答1:
The only value of type ()
is ()
, so just put that inside the Ok
constructor:
fn f() -> Result<(), E> {
Ok(())
}
回答2:
Use Ok(())
as in
fn f() -> Result<(), E> {
Ok(())
}
来源:https://stackoverflow.com/questions/27945858/how-to-return-ok-unit-type-of-stdresult-e