How to unwrap a &Result<_,_>?

前端 未结 1 1197
清酒与你
清酒与你 2020-12-20 21:26

What is a good way to extract data from a &Result type?

In my specific case, I have a &Result type, which I

相关标签:
1条回答
  • 2020-12-20 22:16

    You are looking for Result::as_ref:

    Converts from Result<T, E> to Result<&T, &E>.

    Produces a new Result, containing a reference into the original, leaving the original in place.

    The following code solves your problem:

    let entry: &DirEntry = result.as_ref().unwrap();
    

    For a mutable version, Result::as_mut is provided.

    0 讨论(0)
提交回复
热议问题