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 std::fmt::{self, Display}; 6 use sys_util::Error as SysError; 7 8 #[derive(Debug)] 9 pub enum Error { 10 EventLoopAlreadyFailed, 11 CreateEventFd(SysError), 12 ReadEventFd(SysError), 13 WriteEventFd(SysError), 14 CreatePollContext(SysError), 15 PollContextAddFd(SysError), 16 PollContextDeleteFd(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 CreateEventFd(e) => write!(f, "failed to create event fd: {}", e), 27 ReadEventFd(e) => write!(f, "failed to read event fd: {}", e), 28 WriteEventFd(e) => write!(f, "failed to write event fd: {}", e), 29 CreatePollContext(e) => write!(f, "failed to create poll context: {}", e), 30 PollContextAddFd(e) => write!(f, "failed to add fd to poll context: {}", e), 31 PollContextDeleteFd(e) => write!(f, "failed to delete fd from poll context: {}", e), 32 StartThread(e) => write!(f, "failed to start thread: {}", e), 33 } 34 } 35 } 36 37 pub type Result<T> = std::result::Result<T, Error>; 38