Skip to content

Commit 2a9d649

Browse files
authored
Merge pull request #50 from kornelski/nodesc
Delete description support
2 parents aadd84f + ca9beae commit 2a9d649

File tree

2 files changed

+17
-69
lines changed

2 files changed

+17
-69
lines changed

README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ Here is the comprehensive example:
2424
pub enum IoWrapper {
2525
Io(err: io::Error) {
2626
from()
27-
description("io error")
2827
display("I/O error: {}", err)
2928
cause(err)
3029
}
3130
Other(descr: &'static str) {
32-
description(descr)
3331
display("Error {}", descr)
3432
}
3533
IoAt { place: &'static str, err: io::Error } {
3634
cause(err)
37-
display(me) -> ("{} {}: {}", me.description(), place, err)
38-
description("io error at")
35+
display(me) -> ("io error at {}: {}", place, err)
3936
from(s: String) -> {
4037
place: "some string",
4138
err: io::Error::new(io::ErrorKind::Other, s)

src/lib.rs

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@
4545
//! Now you might have noticed trailing braces `{}`. They are used to define
4646
//! implementations. By default:
4747
//!
48-
//! * `Error::description()` returns variant name as static string
4948
//! * `Error::cause()` returns None (even if type wraps some value)
50-
//! * `Display` outputs `description()`
49+
//! * `Display` outputs debug representation
5150
//! * No `From` implementations are defined
5251
//!
53-
//! To define description simply add `description(value)` inside braces:
54-
//!
5552
//! ```rust
5653
//! # #[macro_use] extern crate quick_error;
5754
//! # fn main() {}
@@ -60,18 +57,15 @@
6057
//! #[derive(Debug)]
6158
//! pub enum SomeError {
6259
//! Io(err: std::io::Error) {
63-
//! description(err.description())
60+
//! display("{}", err)
6461
//! }
6562
//! Utf8(err: std::str::Utf8Error) {
66-
//! description("utf8 error")
63+
//! display("utf8 error")
6764
//! }
6865
//! }
6966
//! }
7067
//! ```
7168
//!
72-
//! Normal rules for borrowing apply. So most of the time description either
73-
//! returns constant string or forwards description from enclosed type.
74-
//!
7569
//! To change `cause` method to return some error, add `cause(value)`, for
7670
//! example:
7771
//!
@@ -84,14 +78,12 @@
8478
//! pub enum SomeError {
8579
//! Io(err: std::io::Error) {
8680
//! cause(err)
87-
//! description(err.description())
8881
//! }
8982
//! Utf8(err: std::str::Utf8Error) {
90-
//! description("utf8 error")
83+
//! display("utf8 error")
9184
//! }
9285
//! Other(err: Box<std::error::Error>) {
9386
//! cause(&**err)
94-
//! description(err.description())
9587
//! }
9688
//! }
9789
//! }
@@ -127,16 +119,16 @@
127119
//! # #[macro_use] extern crate quick_error;
128120
//! # fn main() {}
129121
//! #
130-
//! use std::error::Error; // put methods like `description()` of this trait into scope
122+
//! use std::error::Error; // put methods like `source()` of this trait into scope
131123
//!
132124
//! quick_error! {
133125
//! #[derive(Debug)]
134126
//! pub enum SomeError {
135127
//! Io(err: std::io::Error) {
136-
//! display(x) -> ("{}: {}", x.description(), err)
128+
//! display(x) -> ("I/O: {}", err)
137129
//! }
138130
//! Utf8(err: std::str::Utf8Error) {
139-
//! display(self_) -> ("{}, valid up to {}", self_.description(), err.valid_up_to())
131+
//! display(self_) -> ("UTF-8 error. Valid up to {}", err.valid_up_to())
140132
//! }
141133
//! }
142134
//! }
@@ -256,7 +248,7 @@
256248
//!
257249
//! More info on context in [this article](http://bit.ly/1PsuxDt).
258250
//!
259-
//! All forms of `from`, `display`, `description`, `cause`, and `context`
251+
//! All forms of `from`, `display`, `cause`, and `context`
260252
//! clauses can be combined and put in arbitrary order. Only `from` and
261253
//! `context` can be used multiple times in single variant of enumeration.
262254
//! Docstrings are also okay. Empty braces can be omitted as of quick_error
@@ -379,9 +371,6 @@ macro_rules! quick_error {
379371
}
380372

381373
impl ::std::error::Error for $strname {
382-
fn description(&self) -> &str {
383-
self.0.description()
384-
}
385374
#[allow(deprecated)]
386375
fn cause(&self) -> Option<&::std::error::Error> {
387376
self.0.cause()
@@ -669,20 +658,6 @@ macro_rules! quick_error {
669658
#[allow(unused_doc_comment)]
670659
#[allow(unused_doc_comments)]
671660
impl ::std::error::Error for $name {
672-
fn description(&self) -> &str {
673-
match *self {
674-
$(
675-
$(#[$imeta])*
676-
quick_error!(ITEM_PATTERN
677-
$name $item: $imode [$( ref $var ),*]
678-
) => {
679-
quick_error!(FIND_DESCRIPTION_IMPL
680-
$item: $imode self fmt [$( $var ),*]
681-
{$( $funcs )*})
682-
}
683-
)*
684-
}
685-
}
686661
fn cause(&self) -> Option<&::std::error::Error> {
687662
match *self {
688663
$(
@@ -735,29 +710,21 @@ macro_rules! quick_error {
735710
{ }
736711
) => {
737712
|self_: &$name, f: &mut ::std::fmt::Formatter| {
738-
write!(f, "{}", ::std::error::Error::description(self_))
713+
write!(f, "{:?}", self_)
739714
}
740715
};
741716
(FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
742717
[$( $var:ident ),*]
743718
{ description($expr:expr) $( $tail:tt )*}
744-
) => {
745-
$expr
746-
};
719+
) => {};
747720
(FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
748721
[$( $var:ident ),*]
749722
{ $t:tt $( $tail:tt )*}
750-
) => {
751-
quick_error!(FIND_DESCRIPTION_IMPL
752-
$item: $imode $me $fmt [$( $var ),*]
753-
{$( $tail )*})
754-
};
723+
) => {};
755724
(FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
756725
[$( $var:ident ),*]
757726
{ }
758-
) => {
759-
stringify!($item)
760-
};
727+
) => {};
761728
(FIND_CAUSE_IMPL $item:ident: $imode:tt
762729
[$( $var:ident ),*]
763730
{ cause($expr:expr) $( $tail:tt )*}
@@ -1047,15 +1014,13 @@ mod test {
10471014
fn bare_item_direct() {
10481015
assert_eq!(format!("{}", Bare::One), "One".to_string());
10491016
assert_eq!(format!("{:?}", Bare::One), "One".to_string());
1050-
assert_eq!(Bare::One.description(), "One".to_string());
10511017
assert!(Bare::One.cause().is_none());
10521018
}
10531019
#[test]
10541020
fn bare_item_trait() {
10551021
let err: &Error = &Bare::Two;
10561022
assert_eq!(format!("{}", err), "Two".to_string());
10571023
assert_eq!(format!("{:?}", err), "Two".to_string());
1058-
assert_eq!(err.description(), "Two".to_string());
10591024
assert!(err.cause().is_none());
10601025
}
10611026

@@ -1079,8 +1044,6 @@ mod test {
10791044
"two: hello".to_string());
10801045
assert_eq!(format!("{:?}", Wrapper::from(Wrapped::One)),
10811046
"Wrapper(One)".to_string());
1082-
assert_eq!(Wrapper::from(Wrapped::One).description(),
1083-
"One".to_string());
10841047
}
10851048

10861049
quick_error! {
@@ -1089,19 +1052,16 @@ mod test {
10891052
/// ParseFloat Error
10901053
ParseFloatError(err: ParseFloatError) {
10911054
from()
1092-
description(err.description())
10931055
display("parse float error: {err}", err=err)
10941056
cause(err)
10951057
}
10961058
Other(descr: &'static str) {
1097-
description(descr)
10981059
display("Error: {}", descr)
10991060
}
11001061
/// FromUtf8 Error
11011062
FromUtf8Error(err: Utf8Error, source: Vec<u8>) {
11021063
cause(err)
1103-
display(me) -> ("{desc} at index {pos}: {err}", desc=me.description(), pos=err.valid_up_to(), err=err)
1104-
description("utf8 error")
1064+
display(me) -> ("{desc} at index {pos}: {err}", desc="utf8 error", pos=err.valid_up_to(), err=err)
11051065
from(err: FromUtf8Error) -> (err.utf8_error().clone(), err.into_bytes())
11061066
}
11071067
Discard {
@@ -1119,7 +1079,6 @@ mod test {
11191079
let err = TupleWrapper::ParseFloatError(cause.clone());
11201080
assert_eq!(format!("{}", err), format!("parse float error: {}", cause));
11211081
assert_eq!(format!("{:?}", err), format!("ParseFloatError({:?})", cause));
1122-
assert_eq!(err.description(), cause.description());
11231082
assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
11241083
}
11251084

@@ -1129,7 +1088,6 @@ mod test {
11291088
let err: &Error = &TupleWrapper::Other(desc);
11301089
assert_eq!(format!("{}", err), format!("Error: {}", desc));
11311090
assert_eq!(format!("{:?}", err), format!("Other({:?})", desc));
1132-
assert_eq!(err.description(), desc);
11331091
assert!(err.cause().is_none());
11341092
}
11351093

@@ -1138,9 +1096,8 @@ mod test {
11381096
let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
11391097
let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err().utf8_error();
11401098
let err: &Error = &TupleWrapper::FromUtf8Error(cause.clone(), invalid_utf8.clone());
1141-
assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc=err.description(), pos=cause.valid_up_to(), cause=cause));
1099+
assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc="utf8 error", pos=cause.valid_up_to(), cause=cause));
11421100
assert_eq!(format!("{:?}", err), format!("FromUtf8Error({:?}, {:?})", cause, invalid_utf8));
1143-
assert_eq!(err.description(), "utf8 error");
11441101
assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
11451102
}
11461103

@@ -1166,7 +1123,6 @@ mod test {
11661123
let err: TupleWrapper = From::from("hello");
11671124
assert_eq!(format!("{}", err), format!("Discard"));
11681125
assert_eq!(format!("{:?}", err), format!("Discard"));
1169-
assert_eq!(err.description(), "Discard");
11701126
assert!(err.cause().is_none());
11711127
}
11721128

@@ -1175,7 +1131,6 @@ mod test {
11751131
let err: TupleWrapper = TupleWrapper::Singleton;
11761132
assert_eq!(format!("{}", err), format!("Just a string"));
11771133
assert_eq!(format!("{:?}", err), format!("Singleton"));
1178-
assert_eq!(err.description(), "Singleton");
11791134
assert!(err.cause().is_none());
11801135
}
11811136

@@ -1185,13 +1140,11 @@ mod test {
11851140
// Utf8 Error
11861141
Utf8Error{ err: Utf8Error, hint: Option<&'static str> } {
11871142
cause(err)
1188-
display(me) -> ("{desc} at index {pos}: {err}", desc=me.description(), pos=err.valid_up_to(), err=err)
1189-
description("utf8 error")
1143+
display(me) -> ("{desc} at index {pos}: {err}", desc="utf8 error", pos=err.valid_up_to(), err=err)
11901144
from(err: Utf8Error) -> { err: err, hint: None }
11911145
}
11921146
// Utf8 Error
11931147
ExcessComma { descr: &'static str, } {
1194-
description(descr)
11951148
display("Error: {}", descr)
11961149
}
11971150
}
@@ -1202,9 +1155,8 @@ mod test {
12021155
let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
12031156
let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err().utf8_error();
12041157
let err: &Error = &StructWrapper::Utf8Error{ err: cause.clone(), hint: Some("nonsense") };
1205-
assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc=err.description(), pos=cause.valid_up_to(), cause=cause));
1158+
assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc="utf8 error", pos=cause.valid_up_to(), cause=cause));
12061159
assert_eq!(format!("{:?}", err), format!("Utf8Error {{ err: {:?}, hint: {:?} }}", cause, Some("nonsense")));
1207-
assert_eq!(err.description(), "utf8 error");
12081160
assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
12091161
}
12101162

@@ -1223,7 +1175,6 @@ mod test {
12231175
let err = StructWrapper::ExcessComma { descr: descr };
12241176
assert_eq!(format!("{}", err), format!("Error: {}", descr));
12251177
assert_eq!(format!("{:?}", err), format!("ExcessComma {{ descr: {:?} }}", descr));
1226-
assert_eq!(err.description(), descr);
12271178
assert!(err.cause().is_none());
12281179
}
12291180

0 commit comments

Comments
 (0)