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

Why is Error a Box<ErrorKind>? #202

Closed
Cobrand opened this issue Jul 30, 2017 · 4 comments
Closed

Why is Error a Box<ErrorKind>? #202

Cobrand opened this issue Jul 30, 2017 · 4 comments

Comments

@Cobrand
Copy link
Contributor

@Cobrand Cobrand commented Jul 30, 2017

What makes the Box<_> necessary in the type Error = Box<ErrorKind> definition? As far as I've seen there is no mention of that either in the doc or in the code, and if I recall well it didn't use to have a Box<_> there.

@ZoeyR
Copy link
Collaborator

@ZoeyR ZoeyR commented Jul 30, 2017

I can't find the issue where this was changed at the moment. But if I remember correctly is was an optimization because by boxing up the errors less bytes had to be put on the stack for returns.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jul 31, 2017

@Cobrand: we ran performance tests and found that allocating a Box and copying the box around the stack was cheaper than copying the error value around the stack.

@Cobrand
Copy link
Contributor Author

@Cobrand Cobrand commented Jul 31, 2017

It used to be pretty simple to match all possibilities with one match, now without the (unstable) box pattern you have to use 2 match to get to the same result, that's why I asked why it changed.

Thanks for answering!

@Cobrand Cobrand closed this Jul 31, 2017
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jul 31, 2017

You should be able to use a single * to dereference and then you can match just like before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.