fix: use from trait for encoder, codec, loglevel to u32

This commit is contained in:
Gabriele Musco 2024-08-27 23:27:43 +02:00
commit 4029b4fae5
2 changed files with 26 additions and 20 deletions

View file

@ -36,12 +36,14 @@ impl Encoder {
pub fn as_vec() -> Vec<Self> { pub fn as_vec() -> Vec<Self> {
vec![Self::X264, Self::Nvenc, Self::Vaapi] vec![Self::X264, Self::Nvenc, Self::Vaapi]
} }
}
pub fn as_number(&self) -> u32 { impl From<&Encoder> for u32 {
match self { fn from(value: &Encoder) -> Self {
Self::X264 => 0, match value {
Self::Nvenc => 1, Encoder::X264 => 0,
Self::Vaapi => 2, Encoder::Nvenc => 1,
Encoder::Vaapi => 2,
} }
} }
} }
@ -70,11 +72,13 @@ impl Codec {
pub fn as_vec() -> Vec<Self> { pub fn as_vec() -> Vec<Self> {
vec![Self::H264, Self::H265] vec![Self::H264, Self::H265]
} }
}
pub fn as_number(&self) -> u32 { impl From<&Codec> for u32 {
match self { fn from(value: &Codec) -> Self {
Self::H264 => 0, match value {
Self::H265 => 1, Codec::H264 => 0,
Codec::H265 => 1,
} }
} }
} }

View file

@ -82,16 +82,6 @@ impl LogLevel {
.iter() .iter()
} }
pub fn as_number(&self) -> u32 {
match self {
Self::Trace => 0,
Self::Debug => 1,
Self::Info => 2,
Self::Warning => 3,
Self::Error => 99,
}
}
pub fn colored(&self) -> String { pub fn colored(&self) -> String {
match self { match self {
Self::Trace => TermColor::Gray, Self::Trace => TermColor::Gray,
@ -104,9 +94,21 @@ impl LogLevel {
} }
} }
impl From<&LogLevel> for u32 {
fn from(value: &LogLevel) -> Self {
match value {
LogLevel::Trace => 0,
LogLevel::Debug => 1,
LogLevel::Info => 2,
LogLevel::Warning => 3,
LogLevel::Error => 99,
}
}
}
impl PartialOrd for LogLevel { impl PartialOrd for LogLevel {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.as_number().cmp(&other.as_number())) Some(u32::from(self).cmp(&other.into()))
} }
} }