diff options
| author | Teddy Wing | 2016-04-22 19:03:04 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2016-04-22 19:09:43 -0400 | 
| commit | b9f6915d1e92f77c002f05a1371941dd3e3dcb95 (patch) | |
| tree | c07b8d706ec2b13e93e9237b41a3146c313246fe /src | |
| parent | 4535477b09ff1753cdc83e3c44585ad393a5c716 (diff) | |
| download | mutt-alias-auto-add-b9f6915d1e92f77c002f05a1371941dd3e3dcb95.tar.bz2 | |
Add descriptions to `AliasSearchError` `fmt::Display`
Use the descriptions from our `error::Error` implementation. To do so
needed to `use std::error::Error`.
Change those `write!` calls to `writeln!` also so that we get decent
output on the command line.
We now output errors from `AliasSearchError::{NotFound, EmailExists}` to
STDERR for better error reporting.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 11 | 
1 files changed, 6 insertions, 5 deletions
| diff --git a/src/main.rs b/src/main.rs index 1be35a1..ae7bf17 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::error; +use std::error::{self, Error};  use std::io::{self, BufRead, BufReader, Write};  use std::fmt;  use std::fs::{File, OpenOptions}; @@ -83,9 +83,9 @@ enum AliasSearchError {  impl fmt::Display for AliasSearchError {      fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {          match *self { -            AliasSearchError::NotFound => write!(f, ""), -            AliasSearchError::EmailExists => write!(f, ""), -            AliasSearchError::Io(ref err) => write!(f, "IO error: {}", err), +            AliasSearchError::NotFound => writeln!(f, "{}", self.description()), +            AliasSearchError::EmailExists => writeln!(f, "{}", self.description()), +            AliasSearchError::Io(ref err) => writeln!(f, "IO error: {}", err),          }      }  } @@ -169,7 +169,8 @@ fn main() {          if line.starts_with("From: ") {              match write_alias(line) {                  Ok(_)  => continue, -                Err(AliasSearchError::NotFound) | Err(AliasSearchError::EmailExists) => continue, +                Err(e @ AliasSearchError::NotFound) | Err(e @ AliasSearchError::EmailExists) => +                    io::stderr().write(e.to_string().as_bytes()).ok(),                  Err(e) => io::stderr().write(e.to_string().as_bytes()).ok(),              };          } | 
