Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. extern crate futures;
  2. extern crate futures_cpupool;
  3. extern crate grpc;
  4. extern crate protobuf;
  5. extern crate tokio_timer;
  6.  
  7. pub mod client;
  8. pub mod client_grpc;
  9.  
  10. use futures::Future;
  11. use futures::MapErr;
  12.  
  13. use std::error::Error;
  14.  
  15. use std::fmt::Result as FmtResult;
  16. use std::fmt::Display;
  17. use std::fmt::Formatter;
  18.  
  19. use grpc::error::GrpcError;
  20. use grpc::futures_grpc::GrpcFutureSend;
  21.  
  22. use tokio_timer::TimeoutError;
  23.  
  24. use client::TestResponse;
  25.  
  26. #[derive(Debug)]
  27. pub enum TestError {
  28. Grpc(GrpcError),
  29. Timeout,
  30. }
  31.  
  32. impl Error for TestError {
  33. fn description(&self) -> &str {
  34. match *self {
  35. TestError::Grpc(ref grpc_error) => grpc_error.description(),
  36. TestError::Timeout => "operation timed out",
  37. }
  38. }
  39.  
  40. fn cause(&self) -> Option<&Error> {
  41. match *self {
  42. TestError::Grpc(ref grpc_error) => grpc_error.cause(),
  43. TestError::Timeout => None,
  44. }
  45. }
  46. }
  47.  
  48. impl Display for TestError {
  49. fn fmt(&self, f: &mut Formatter) -> FmtResult {
  50. match *self {
  51. TestError::Grpc(ref grpc_error) => grpc_error.fmt(f),
  52. TestError::Timeout => write!(f, "operation timed out"),
  53. }
  54. }
  55. }
  56.  
  57. impl<F> From<TimeoutError<MapErr<Box<Future<Error=GrpcError, Item=TestResponse> + Send>, F>>> for TestError
  58. where F: FnOnce (GrpcError) -> TestError {
  59. fn from(err: TimeoutError<MapErr<Box<Future<Error=GrpcError, Item=TestResponse> + Send>, F>>) -> Self {
  60. TestError::Timeout
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement