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

前端 未结 2 1674
梦如初夏
梦如初夏 2021-02-19 13:33

If I define a function:

fn f() -> Result<(), E> {
    // How to return Ok()?
}

How can I return the Ok in std::resu

相关标签:
2条回答
  • 2021-02-19 13:48

    Use Ok(()) as in

    fn f() -> Result<(), E> {
        Ok(())
    }
    
    0 讨论(0)
  • 2021-02-19 14:13

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

    fn f() -> Result<(), E> {
        Ok(())
    }
    
    0 讨论(0)
提交回复
热议问题