use core::fmt;
use core::fmt::Display;
#[cfg(feature = "std")]
use std::error;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u64)]
pub enum PoolState {
Active = 0,
Exported = 1,
Destroyed = 2,
Spare = 3,
L2Cache = 4,
}
impl Display for PoolState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoolState::Active => write!(f, "Active"),
PoolState::Exported => write!(f, "Exported"),
PoolState::Destroyed => write!(f, "Destroyed"),
PoolState::Spare => write!(f, "Spare"),
PoolState::L2Cache => write!(f, "L2Cache"),
}
}
}
impl From<PoolState> for u64 {
fn from(val: PoolState) -> u64 {
val as u64
}
}
impl TryFrom<u64> for PoolState {
type Error = PoolStateDecodeError;
fn try_from(pool_state: u64) -> Result<Self, Self::Error> {
match pool_state {
0 => Ok(PoolState::Active),
1 => Ok(PoolState::Exported),
2 => Ok(PoolState::Destroyed),
3 => Ok(PoolState::Spare),
4 => Ok(PoolState::L2Cache),
_ => Err(PoolStateDecodeError::Unknown { pool_state }),
}
}
}
#[derive(Debug)]
pub enum PoolStateDecodeError {
Unknown {
pool_state: u64,
},
}
impl fmt::Display for PoolStateDecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoolStateDecodeError::Unknown { pool_state } => {
write!(f, "PoolState decode error, unknown state {pool_state}")
}
}
}
}
#[cfg(feature = "std")]
impl error::Error for PoolStateDecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u64)]
pub enum PoolErrata {
None = 0,
Zol2094Scrub = 1,
Zol2094AsyncDestroy = 2,
Zol6845Encryption = 3,
Zol8308Encryption = 4,
}
impl Display for PoolErrata {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoolErrata::None => write!(f, "None"),
PoolErrata::Zol2094Scrub => write!(f, "Zol2094Scrub"),
PoolErrata::Zol2094AsyncDestroy => write!(f, "Zol2094AsyncDestroy"),
PoolErrata::Zol6845Encryption => write!(f, "Zol6845Encryption"),
PoolErrata::Zol8308Encryption => write!(f, "Zol8308Encryption"),
}
}
}
impl From<PoolErrata> for u64 {
fn from(val: PoolErrata) -> u64 {
val as u64
}
}
impl TryFrom<u64> for PoolErrata {
type Error = PoolErrataDecodeError;
fn try_from(pool_errata: u64) -> Result<Self, Self::Error> {
match pool_errata {
0 => Ok(PoolErrata::None),
1 => Ok(PoolErrata::Zol2094Scrub),
2 => Ok(PoolErrata::Zol2094AsyncDestroy),
3 => Ok(PoolErrata::Zol6845Encryption),
4 => Ok(PoolErrata::Zol8308Encryption),
_ => Err(PoolErrataDecodeError::Unknown { pool_errata }),
}
}
}
#[derive(Debug)]
pub enum PoolErrataDecodeError {
Unknown {
pool_errata: u64,
},
}
impl fmt::Display for PoolErrataDecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoolErrataDecodeError::Unknown { pool_errata } => {
write!(f, "PoolErrata decode error, unknown errata {pool_errata}")
}
}
}
}
#[cfg(feature = "std")]
impl error::Error for PoolErrataDecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PoolConfigKey {
AllocateShift,
Comment,
Compatibility,
Errata,
FeaturesForRead,
Guid,
HostId,
HostName,
IsLog,
IsSpare,
Name,
PoolGuid,
SplitGuid,
State,
TopGuid,
Txg,
VdevChildren,
VdevTree,
Version,
}
impl PoolConfigKey {
const ALL: [PoolConfigKey; 18] = [
PoolConfigKey::AllocateShift,
PoolConfigKey::Comment,
PoolConfigKey::Compatibility,
PoolConfigKey::Errata,
PoolConfigKey::FeaturesForRead,
PoolConfigKey::Guid,
PoolConfigKey::HostId,
PoolConfigKey::HostName,
PoolConfigKey::IsLog,
PoolConfigKey::IsSpare,
PoolConfigKey::Name,
PoolConfigKey::PoolGuid,
PoolConfigKey::State,
PoolConfigKey::TopGuid,
PoolConfigKey::Txg,
PoolConfigKey::VdevChildren,
PoolConfigKey::VdevTree,
PoolConfigKey::Version,
];
pub fn all() -> &'static [PoolConfigKey] {
&PoolConfigKey::ALL
}
}
impl Display for PoolConfigKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s: &'static str = (*self).into();
write!(f, "{s}")
}
}
impl From<PoolConfigKey> for &'static str {
fn from(val: PoolConfigKey) -> &'static str {
match val {
PoolConfigKey::AllocateShift => "ashift",
PoolConfigKey::Comment => "comment",
PoolConfigKey::Compatibility => "compatibility",
PoolConfigKey::Errata => "errata",
PoolConfigKey::FeaturesForRead => "features_for_read",
PoolConfigKey::Guid => "guid",
PoolConfigKey::HostId => "hostid",
PoolConfigKey::HostName => "hostname",
PoolConfigKey::IsLog => "is_log",
PoolConfigKey::IsSpare => "is_spare",
PoolConfigKey::Name => "name",
PoolConfigKey::PoolGuid => "pool_guid",
PoolConfigKey::SplitGuid => "split_guid",
PoolConfigKey::State => "state",
PoolConfigKey::TopGuid => "top_guid",
PoolConfigKey::Txg => "txg",
PoolConfigKey::VdevChildren => "vdev_children",
PoolConfigKey::VdevTree => "vdev_tree",
PoolConfigKey::Version => "version",
}
}
}
impl TryFrom<&str> for PoolConfigKey {
type Error = PoolConfigKeyDecodeError;
fn try_from(feature: &str) -> Result<Self, Self::Error> {
match feature {
"comment" => Ok(PoolConfigKey::Comment),
"compatibility" => Ok(PoolConfigKey::Compatibility),
"errata" => Ok(PoolConfigKey::Errata),
"features_for_read" => Ok(PoolConfigKey::FeaturesForRead),
"guid" => Ok(PoolConfigKey::Guid),
"hostid" => Ok(PoolConfigKey::HostId),
"hostname" => Ok(PoolConfigKey::HostName),
"is_log" => Ok(PoolConfigKey::IsLog),
"is_spare" => Ok(PoolConfigKey::IsSpare),
"name" => Ok(PoolConfigKey::Name),
"pool_guid" => Ok(PoolConfigKey::PoolGuid),
"split_guid" => Ok(PoolConfigKey::SplitGuid),
"state" => Ok(PoolConfigKey::State),
"top_guid" => Ok(PoolConfigKey::TopGuid),
"txg" => Ok(PoolConfigKey::Txg),
"vdev_children" => Ok(PoolConfigKey::VdevChildren),
"vdev_tree" => Ok(PoolConfigKey::VdevTree),
"version" => Ok(PoolConfigKey::Version),
_ => Err(PoolConfigKeyDecodeError::Unknown {}),
}
}
}
#[derive(Debug)]
pub enum PoolConfigKeyDecodeError {
Unknown {},
}
impl fmt::Display for PoolConfigKeyDecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PoolConfigKeyDecodeError::Unknown {} => {
write!(f, "PoolConfigKey decode error, unknown key")
}
}
}
}
#[cfg(feature = "std")]
impl error::Error for PoolConfigKeyDecodeError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}