summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-05-26 21:59:33 +0200
committerLaurenz <laurmaedje@gmail.com>2019-05-26 21:59:33 +0200
commitc38e17d91f81632422171b8103ce90baacfdbe22 (patch)
tree757387b885bd5f0785dbafbf1704fb280dd4a269 /src/error.rs
parentb3734bbc046fe7b14cff54e2dae7014a71014777 (diff)
Thoroughly improve documentation 📝
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs
index 442971d0..514eb1a8 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -2,13 +2,19 @@
/// Create an error type.
macro_rules! error_type {
- (
+ ( // The variable used instead of self in functions
+ // followed by the error type things are happening on.
$var:ident: $err:ident,
+ // Optionally the name of a result type to generate.
$(res: $res:ident,)*
+ // A `Display` and `Debug` implementation.
show: $f:ident => $show:expr,
+ // Optionally a `source` function for the `std::error::Error` trait.
$(source: $source:expr,)*
+ // Any number of `From` implementations.
$(from: ($from:path, $conv:expr),)*
) => {
+ // Possibly create a result type.
$(type $res<T> = std::result::Result<T, $err>;)*
impl std::fmt::Display for $err {
@@ -25,12 +31,14 @@ macro_rules! error_type {
}
impl std::error::Error for $err {
+ // The source method is only generated if an implementation was given.
$(fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
let $var = self;
$source
})*
}
+ // Create any number of from implementations.
$(impl From<$from> for $err {
fn from($var: $from) -> $err {
$conv