use std::fmt;
use std::str::FromStr;
#[derive(Debug, PartialEq)]
pub enum FsType {
Proc,
Overlay,
Tmpfs,
Sysfs,
Btrfs,
Ext2,
Ext3,
Ext4,
Devtmpfs,
Other(String),
}
impl FromStr for FsType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"proc" => Ok(FsType::Proc),
"tmpfs" => Ok(FsType::Tmpfs),
"overlay" => Ok(FsType::Overlay),
"sysfs" => Ok(FsType::Sysfs),
"btrfs" => Ok(FsType::Btrfs),
"ext2" => Ok(FsType::Ext2),
"ext3" => Ok(FsType::Ext3),
"ext4" => Ok(FsType::Ext4),
"devtmpfs" => Ok(FsType::Devtmpfs),
_ => Ok(FsType::Other(s.to_string())),
}
}
}
impl fmt::Display for FsType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let fsname = match self {
FsType::Proc => "proc",
FsType::Overlay => "overlay",
FsType::Tmpfs => "tmpfs",
FsType::Sysfs => "sysfs",
FsType::Btrfs => "btrfs",
FsType::Ext2 => "ext2",
FsType::Ext3 => "ext3",
FsType::Ext4 => "ext4",
FsType::Devtmpfs => "devtmpfs",
FsType::Other(fsname) => fsname,
};
write!(f, "{}", fsname)
}
}