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

Self-by-value builders returning ownership of the builder after an error #82

Open
dtolnay opened this Issue May 31, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@dtolnay
Copy link
Member

dtolnay commented May 31, 2017

impl MyBuilder {
    fn f(self, /* ... */) -> Result<Self, Error> { /* ... */ }
}

The user may not be able to tell ahead of time whether the arguments passed to f will result in an error. They may want to handle the error but continue to use the same builder as though f had not been called, which is typically possible with a &mut self builder.

Thus it can be a good idea for the error type to provide access to the builder that failed. This is similar to the idea behind FromUtf8Error::into_bytes that returns ownership of the bytes that failed UTF-8 conversion.

Need to be careful with Send and Sync though. Error types are expected to be Send and Sync but the builder may not be, so it may not be possible to stash the builder inside of the error type.

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.