Skip to content

Commit 935ed6b

Browse files
committed
Add Debug implementation
1 parent 6e4fc47 commit 935ed6b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ macro_rules! quick_error {
776776
}
777777

778778

779+
#[derive(Debug)]
779780
pub struct Context<X, E>(pub X, pub E);
780781

781782
pub trait ResultExt<T, E> {
@@ -999,4 +1000,14 @@ mod test {
9991000
assert_eq!(format!("{}", parse_int("12.5").unwrap_err()),
10001001
r#"Int error "12.5": invalid digit found in string"#);
10011002
}
1003+
1004+
#[test]
1005+
fn debug_context() {
1006+
fn parse_int(s: &str) -> i32 {
1007+
s.parse().context(s).unwrap()
1008+
}
1009+
assert_eq!(parse_int("12"), 12);
1010+
assert_eq!(format!("{:?}", "x".parse::<i32>().context("x")),
1011+
r#"Err(Context("x", ParseIntError { kind: InvalidDigit }))"#);
1012+
}
10021013
}

0 commit comments

Comments
 (0)