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

[rfc] add methods for extracting `diesel::result::Error::NotFound` #1843

Closed
derekdreery opened this Issue Sep 11, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@derekdreery
Contributor

derekdreery commented Sep 11, 2018

I am proposing something like the following

// in `diesel::result`

pub trait ResultExt<T> {
    pub extract_not_found(self) -> Result<Option<T>, Error>;
}

impl<T> ResultExt<T> for Result<T, Error> {
    pub extract_not_found(self) -> Result<Option<T>, Error> {
        match self {
            Ok(t) => Ok(Some(t)),
            Err(Error::NotFound) => Ok(None),
            Err(e) => Err(e)
        }
    }
}

Checklist

  • I have already looked over the issue tracker for similar issues. Apologies if I missed anything.
@sgrif

This comment has been minimized.

@sgrif sgrif closed this Sep 11, 2018

@derekdreery

This comment has been minimized.

Contributor

derekdreery commented Sep 11, 2018

Urgh, I was sure I'd looked. Apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment