aio_limited/
error.rs

1// Copyright 2018 Parity Technologies (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 or MIT license, at your option.
4//
5// A copy of the Apache License, Version 2.0 is included in the software as
6// LICENSE-APACHE and a copy of the MIT license is included in the software
7// as LICENSE-MIT. You may also obtain a copy of the Apache License, Version 2.0
8// at https://www.apache.org/licenses/LICENSE-2.0 and a copy of the MIT license
9// at https://opensource.org/licenses/MIT.
10
11use std::{fmt, io};
12use tokio_executor::SpawnError;
13
14pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Debug)]
17pub enum Error {
18    Io(io::Error),
19    Exec(SpawnError),
20    NoCapacity,
21    TimerError,
22
23    #[doc(hidden)]
24    __Nonexhaustive
25}
26
27impl fmt::Display for Error {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        match self {
30            Error::Io(e) => write!(f, "i/o error: {}", e),
31            Error::Exec(e) => write!(f, "spawn error: {}", e),
32            Error::NoCapacity => f.write_str("no capacity left"),
33            Error::TimerError => f.write_str("error executing background timer"),
34            Error::__Nonexhaustive => f.write_str("__Nonexhaustive")
35        }
36    }
37}
38
39impl std::error::Error for Error {
40    fn cause(&self) -> Option<&dyn std::error::Error> {
41        match self {
42            Error::Io(e) => Some(e),
43            Error::Exec(e) => Some(e),
44            _ => None
45        }
46    }
47}
48
49
50impl From<io::Error> for Error {
51    fn from(e: io::Error) -> Self {
52        Error::Io(e)
53    }
54}
55
56impl From<SpawnError> for Error {
57    fn from(e: SpawnError) -> Self {
58        Error::Exec(e)
59    }
60}