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 ()
?
The only value of type ()
is ()
, so just put that inside the Ok
constructor:
fn f() -> Result<(), E> {
Ok(())
}
Use Ok(())
as in
fn f() -> Result<(), E> {
Ok(())
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.