use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
pub enum FileFlushMode {
Data,
DataAndMetadata,
}
impl FileFlushMode {
fn rank(&self) -> u8 {
match self {
Self::Data => 0,
Self::DataAndMetadata => 1,
}
}
fn debug_name(&self) -> &'static str {
match self {
Self::Data => "Data",
Self::DataAndMetadata => "DataAndMetadata",
}
}
fn display_name(&self) -> &'static str {
match self {
Self::Data => "data",
Self::DataAndMetadata => "data-and-metadata",
}
}
}
impl fmt::Debug for FileFlushMode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.debug_name())
}
}
impl fmt::Display for FileFlushMode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.display_name())
}
}
impl PartialEq for FileFlushMode {
fn eq(&self, other: &Self) -> bool {
self.rank() == other.rank()
}
}
impl Eq for FileFlushMode {}
impl PartialOrd for FileFlushMode {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for FileFlushMode {
fn cmp(&self, other: &Self) -> Ordering {
self.rank().cmp(&other.rank())
}
}
impl Hash for FileFlushMode {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.rank().hash(state);
}
}