Files
darkfi/src/net/error.rs
rachel-rose caaeecc36b refactored src/error.rs to work with 'clone'. changed error macros in
async-serial.rs and serial.rs to reflect this change. updated all files
with new error handling.
2021-05-20 11:44:38 +02:00

31 lines
969 B
Rust

use std::fmt;
/// Returns the relevant network error if a program fails.
pub type NetResult<T> = std::result::Result<T, NetError>;
/// An enum representing the main network errors.
#[derive(Debug, Clone)]
pub enum NetError {
OperationFailed,
ConnectFailed,
ConnectTimeout,
ChannelStopped,
ChannelTimeout,
ServiceStopped,
}
impl std::error::Error for NetError {}
impl fmt::Display for NetError {
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
match *self {
NetError::OperationFailed => f.write_str("Operation failed"),
NetError::ConnectFailed => f.write_str("Connection failed"),
NetError::ConnectTimeout => f.write_str("Connection timed out"),
NetError::ChannelStopped => f.write_str("Channel stopped"),
NetError::ChannelTimeout => f.write_str("Channel timed out"),
NetError::ServiceStopped => f.write_str("Service stopped"),
}
}
}