1 // Copyright 2018 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use base::Error as SysError;
6 use std::fmt::{self, Display};
7 
8 #[derive(Debug)]
9 pub enum Error {
10     EventLoopAlreadyFailed,
11     CreateEvent(SysError),
12     ReadEvent(SysError),
13     WriteEvent(SysError),
14     CreateWaitContext(SysError),
15     WaitContextAddDescriptor(SysError),
16     WaitContextDeleteDescriptor(SysError),
17     StartThread(std::io::Error),
18 }
19 
20 impl Display for Error {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result21     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22         use self::Error::*;
23 
24         match self {
25             EventLoopAlreadyFailed => write!(f, "event loop already failed due to previous errors"),
26             CreateEvent(e) => write!(f, "failed to create event: {}", e),
27             ReadEvent(e) => write!(f, "failed to read event: {}", e),
28             WriteEvent(e) => write!(f, "failed to write event: {}", e),
29             CreateWaitContext(e) => write!(f, "failed to create poll context: {}", e),
30             WaitContextAddDescriptor(e) => write!(f, "failed to add fd to poll context: {}", e),
31             WaitContextDeleteDescriptor(e) => {
32                 write!(f, "failed to delete fd from poll context: {}", e)
33             }
34             StartThread(e) => write!(f, "failed to start thread: {}", e),
35         }
36     }
37 }
38 
39 pub type Result<T> = std::result::Result<T, Error>;
40