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

Add modifiers for error code and class (#576) #579

Merged
merged 5 commits into from Jun 26, 2020

Conversation

kim
Copy link
Contributor

@kim kim commented Jun 25, 2020

Arguably the most naive / liberal way to allow for custom errors. There might be reasons to only allow a subset of the error codes / classes, but I can't make up my mind which ones that should be. If that's the case, perhaps a set of specialised constructors would be preferrable, otherwise I'd lean towards amending this to define a new constructor which takes the code and class directly.

Aside: I noticed that the ErrorCode enum is missing some possible values from the binding. I'll submit that separately.

@alexcrichton
Copy link
Member

Thanks! Could these take &mut self though since I think that's more idiomatic?

@kim
Copy link
Contributor Author

kim commented Jun 25, 2020

I think that's more idiomatic

I'm seeing "setters" used in a few different flavours across the ecosystem, so I can't tell, really :) mut Self -> Self, &mut self -> &mut Self, and &mut self -> () all yield very different ergonomics, and I chose the first because I figured that one would mostly want to construct custom errors, not actually modify them. So, what do you think of just new(class, code, message) or custom(...)?

@alexcrichton
Copy link
Member

Adding new also sounds good to me! Typically with what I've seen with_x is self -> self while set_x is just &mut self -> (). Builder-style x is where &mut self -> &mut self comes into play

@alexcrichton alexcrichton merged commit 6aebca0 into rust-lang:master Jun 26, 2020
@alexcrichton
Copy link
Member

Thanks!

@kim kim mentioned this pull request Jun 27, 2020
@kim kim deleted the custom-error branch June 29, 2020 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants