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

前端 未结 2 1670
梦如初夏
梦如初夏 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 14:13

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

    fn f() -> Result<(), E> {
        Ok(())
    }
    

提交回复
热议问题