#![deny(missing_docs)]
use std::{io, str};
#[derive(Debug)]
pub enum Error {
Io(io::Error),
Utf8ToStr(str::Utf8Error),
Attach,
Detach,
Wait
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Attach|Self::Detach|Self::Wait => None,
Self::Io(ref source) => Some(source),
Self::Utf8ToStr(ref source) => Some(source),
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Self::Attach => {
write!(f, "Failed to attach to wpasupplicant")
}
Self::Detach => {
write!(f, "Failed to detach from wpasupplicant")
}
Self::Wait => {
write!(f, "Unable to wait for response from wpasupplicant")
}
Self::Io(ref err) => {
write!(f, "Failed to execute the specified command: {}", err)
}
Self::Utf8ToStr(ref err) => {
write!(f, "Failed to parse UTF8 to string: {}", err)
}
}
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Self::Io(err)
}
}
impl From<str::Utf8Error> for Error {
fn from(err: str::Utf8Error) -> Self {
Self::Utf8ToStr(err)
}
}