Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::option::NoneError, what to do? #61

Closed
stephanbuys opened this Issue Nov 18, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@stephanbuys
Copy link

stephanbuys commented Nov 18, 2017

Hi, I scoured the docs and had a bit of a hard time discerning if Failure should handle the NoneError type that can be returned when a you call to_str() on a PathBuf, I'm migrating my code from error_chain and I used the .chain_error() method to convert these errors into compatible types. Am I missing something or should I implement From fro NoneError?

@Celti

This comment has been minimized.

Copy link

Celti commented Nov 18, 2017

As I just discovered a couple hours ago (see #59), NoneError can not implement Fail at this time, because it lacks an implementation of Display (and we can't simply derive both because it's an external type, AIUI). This could be fixed if NoneError gains an impl of Display or of std::error::Error.

If you're using the Error and ErrorKind pattern for failure, you could easily implement From<NoneError> for your own Error type. The crates I'm working on haven't grown to needing their own Error type yet, and I'm too lazy to do that just for NoneError, so I'm sticking with Option::ok_or(err_msg("Option did not contain a value.")) for now.

@stephanbuys

This comment has been minimized.

Copy link
Author

stephanbuys commented Nov 18, 2017

Thank you - I'm also in the early stages and don't need Error types yet, so I ok_or it is.

@U007D

This comment has been minimized.

Copy link
Contributor

U007D commented Mar 16, 2018

If you're using the Error and ErrorKind pattern for failure, you could easily implement From for your own Error type.

@Celti can you elaborate on this? I am implementing my custom error type:

#[derive(Fail, Debug)]
enum MyError {
    Variant1,
}

// impl Display for MyError

impl From<NoneError> for MyError {
    fn from(err: NoneError) -> Self {
        MyError::Variant1
    }
}

gives the trait bound std::option::NoneError: std::error::Error is not satisfied when I try to use the error check operator: foo()? (where fn foo() -> Option<T>).

How to work around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.