-
Notifications
You must be signed in to change notification settings - Fork 111
Shrink the size of all Error
types
#225
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,7 +255,7 @@ fn error_chain_err() { | |
let base = Error::from(ErrorKind::Test); | ||
let ext = base.chain_err(|| "Test passes"); | ||
|
||
if let Error(ErrorKind::Msg(_), _) = ext { | ||
if let ErrorKind::Msg(_) = *ext.kind() { | ||
// pass | ||
} else { | ||
panic!("The error should be wrapped. {:?}", ext); | ||
|
@@ -484,8 +484,8 @@ fn error_patterns() { | |
} | ||
|
||
// Tuples look nice when matching errors | ||
match Error::from("Test") { | ||
Error(ErrorKind::Msg(_), _) => {}, | ||
match *Error::from("Test").kind() { | ||
ErrorKind::Msg(_) => {}, | ||
_ => {}, | ||
} | ||
} | ||
|
@@ -500,8 +500,12 @@ fn result_match() { | |
|
||
match ok() { | ||
Ok(()) => {}, | ||
Err(Error(ErrorKind::Msg(_), _)) => {}, | ||
Err(..) => {}, | ||
Err(e) => { | ||
match *e.kind() { | ||
ErrorKind::Msg(_) => {} | ||
_ => {} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very satisfied with this new behaviour, it's less straightforward. Not sure how to improve it though... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. box_patterns will be stabilized some day, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yamakaky do you have a preferred method of how we might land this? I'd personally like to see this as at least an option, it's what I'd want for libraries 99% of the time I believe. |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we can't pattern match on the kind (
box
if nightly only), maybe we could removepub
and put everything into$crate
asI tried that at one time, but it was rejected because it prohibited the use of pattern matching. But if we can't use it anyway...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in the usage I've seen I think it's quite important to match on
ErrorKind
, but is matching on the entire error itself that important?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes : https://github.com/rust-lang-nursery/error-chain/blob/master/src/lib.rs#L348-L353
With the new method, you can't do that anymore. You have to match on Result, then on error.kind().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong link. Adding #226
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, yes.