Search code examples
error-handlingrustglobownership

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


I have a glob::GlobError from the glob crate. There's an underlying io::Error that I need. How do I get it? There's a few methods available, such as this one:

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

However, it just returns a reference. I need to own it, since I want to put it into another error struct that requires ownership.

An other options is this:

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

Same problem with the reference, and on top it's the wrong error type.

It it possible to get an io::Error somehow?


Solution

  • You're looking at outdated documentation.

    Go to the latest version, there's a pub fn into_error(self) -> Error.