error.rs 994 B

123456789101112131415161718192021222324252627282930
  1. use std::fmt;
  2. /// Returns the relevant network error if a program fails.
  3. pub type NetResult<T> = std::result::Result<T, NetError>;
  4. /// Defines a set of common network errors. Used for error handling.
  5. #[derive(Debug, Copy, Clone)]
  6. pub enum NetError {
  7. OperationFailed,
  8. ConnectFailed,
  9. ConnectTimeout,
  10. ChannelStopped,
  11. ChannelTimeout,
  12. ServiceStopped,
  13. }
  14. impl std::error::Error for NetError {}
  15. impl fmt::Display for NetError {
  16. fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
  17. match *self {
  18. NetError::OperationFailed => f.write_str("Operation failed"),
  19. NetError::ConnectFailed => f.write_str("Connection failed"),
  20. NetError::ConnectTimeout => f.write_str("Connection timed out"),
  21. NetError::ChannelStopped => f.write_str("Channel stopped"),
  22. NetError::ChannelTimeout => f.write_str("Channel timed out"),
  23. NetError::ServiceStopped => f.write_str("Service stopped"),
  24. }
  25. }
  26. }