use core::result::Result as StdResult;
use thiserror::Error as ThisError;
#[derive(Debug)]
#[non_exhaustive]
pub enum ShareStatus {
Nop,
NotConnected,
NotSynced,
CannotShareRoot,
Ok,
}
#[derive(Debug, ThisError)]
#[non_exhaustive]
pub enum Error {
#[error("failed to parse status: {0}")]
ParsingFailed(String),
}
impl TryFrom<&str> for ShareStatus {
type Error = Error;
fn try_from(value: &str) -> StdResult<Self, Self::Error> {
Ok(match value {
"NOP" => Self::Nop,
"NOTCONNECTED" => Self::NotConnected,
"NOTSYNCED" => Self::NotSynced,
"CANNOTSHAREROOT" => Self::CannotShareRoot,
"OK" => Self::Ok,
_ => return Err(Error::ParsingFailed(format!("invalid status: {value}"))),
})
}
}