How to return Ok unit type of std::result<(), E>?
Asked Answered
E

2

20

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

Epidote answered 14/1, 2015 at 14:58 Comment(0)
B
28

The only value of type () is (), so just put that inside the Ok constructor:

fn f() -> Result<(), E> {
    Ok(())
}
Binny answered 14/1, 2015 at 15:5 Comment(0)
E
7

Use Ok(()) as in

fn f() -> Result<(), E> {
    Ok(())
}
Epidote answered 14/1, 2015 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.