mirror of
https://github.com/icewind1991/notify-redis.git
synced 2026-06-03 18:24:12 +02:00
error formatting
This commit is contained in:
parent
5346518168
commit
a19f406505
1 changed files with 23 additions and 2 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -4,6 +4,9 @@ use std::env;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::fmt;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum WatchError {
|
enum WatchError {
|
||||||
|
|
@ -23,6 +26,24 @@ impl From<redis::RedisError> for WatchError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for WatchError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
WatchError::Redis(err) => err.fmt(f),
|
||||||
|
WatchError::Notify(err) => err.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error for WatchError {
|
||||||
|
fn cause(&self) -> Option<&Error> {
|
||||||
|
match self {
|
||||||
|
WatchError::Redis(err) => Some(err),
|
||||||
|
WatchError::Notify(err) => Some(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn watch(path: &str, redis_connect: &str, redis_list: &str) -> Result<(), WatchError> {
|
fn watch(path: &str, redis_connect: &str, redis_list: &str) -> Result<(), WatchError> {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
|
|
@ -35,7 +56,7 @@ fn watch(path: &str, redis_connect: &str, redis_list: &str) -> Result<(), WatchE
|
||||||
loop {
|
loop {
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
Ok(event) => push_event(event, &con, redis_list)?,
|
Ok(event) => push_event(event, &con, redis_list)?,
|
||||||
Err(e) => println!("watch error: {:?}", e),
|
Err(e) => println!("watch error: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +88,7 @@ fn main() {
|
||||||
let args: Vec<_> = env::args().collect();
|
let args: Vec<_> = env::args().collect();
|
||||||
if let [_, path, redis, list] = args.as_slice() {
|
if let [_, path, redis, list] = args.as_slice() {
|
||||||
if let Err(e) = watch(path, redis, list) {
|
if let Err(e) = watch(path, redis, list) {
|
||||||
println!("error: {:?}", e)
|
println!("error: {}", e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("usage: {} <path> <redis_connect> <redis_list>", args[0])
|
println!("usage: {} <path> <redis_connect> <redis_list>", args[0])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue