Skip to main content

opentracingrust/
errors.rs

1use std::error::Error as StdError;
2use std::fmt;
3use std::io;
4use std::num;
5use std::result;
6
7use crossbeam_channel::SendError;
8
9use super::span::FinishedSpan;
10
11/// Enumeration of all errors returned by OpenTracingRust.
12#[derive(Debug)]
13pub enum Error {
14    IoError(self::io::Error),
15    Msg(String),
16    ParseIntError(self::num::ParseIntError),
17    SendError(self::SendError<FinishedSpan>)
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22        match self {
23            Error::IoError(ref io) => fmt::Display::fmt(io, f),
24            Error::Msg(ref msg) => fmt::Display::fmt(msg, f),
25            Error::ParseIntError(ref parse) => fmt::Display::fmt(parse, f),
26            Error::SendError(ref send) => fmt::Display::fmt(send, f),
27        }
28    }
29}
30
31impl StdError for Error {}
32
33impl From<self::io::Error> for Error {
34    fn from(error: io::Error) -> Self {
35        Error::IoError(error)
36    }
37}
38
39impl From<self::num::ParseIntError> for Error {
40    fn from(error: self::num::ParseIntError) -> Self {
41        Error::ParseIntError(error)
42    }
43}
44
45impl From<self::SendError<FinishedSpan>> for Error {
46    fn from(error: self::SendError<FinishedSpan>) -> Self {
47        Error::SendError(error)
48    }
49}
50
51/// Type alias for `Result`s that can fail with an OpenTracingRust `Error`.
52pub type Result<T> = self::result::Result<T, Error>;