如何返回 std::result<(), E> 的 Ok 单位类型?

如何返回 std::result<(), E> 的 Ok 单位类型?

问题描述:

如果我定义一个函数:

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

如何返回 std::result 中单元类型为 ()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(())
}