如何在 Rust 中将 glob::GlobError 变成 io::Error?

How do I turn a glob::GlobError into an io::Error in Rust?

我有一个 glob::GlobError from the glob crate. There's an underlying io::Error 需要。我如何得到它?有几种方法可用,比如这个:

fn error(&self) -> &io::Error

不过,它只是returns一个参考。我需要拥有它,因为我想将它放入另一个需要所有权的错误结构中。

另一个选项是:

fn cause(&self) -> Option<&std::error::Error>

与参考相同的问题,最重要的是错误类型。

有没有可能得到一个io::Error

您正在查看过时的文档。

转到最新版本,有一个pub fn into_error(self) -> Error