tower-watch: Add Error impls for tower_watch::Error (#90)

This branch adds `std::fmt::Display` and `std::error::Error` impls
to `tower-watch`'s `Error` type.

This is necessary to adopt `tower-watch` in Linkerd 2's proxy
(rather than our internal implementation of a similar type), as 
the errors will be part of an error chain which requires these
traits.
This commit is contained in:
Eliza Weisman 2018-12-13 15:02:27 -08:00 committed by GitHub
parent ffa6f03618
commit 075ffb3725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -3,6 +3,7 @@ extern crate futures;
extern crate futures_watch;
extern crate tower_service;
use std::{fmt, error};
use futures::{Async, Future, Poll, Stream};
use futures_watch::{Watch, WatchError};
use tower_service::Service;
@ -75,6 +76,32 @@ where
}
}
// ==== impl Error ====
impl<E> fmt::Display for Error<E>
where
E: fmt::Display
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::WatchError(_) => f.pad("watch error"),
Error::Inner(e) => fmt::Display::fmt(e, f),
}
}
}
impl<E> error::Error for Error<E>
where
E: error::Error,
{
fn cause(&self) -> Option<&error::Error> {
match self {
Error::WatchError(_) => None,
Error::Inner(e) => e.cause(),
}
}
}
// ==== impl Bind<T> ====
impl<T, S, F> Bind<T> for F