mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-17 09:33:38 -05:00
V3
Many many many changes, honestly just read the release notes
This commit is contained in:
42
src/structs/status.rs
Normal file
42
src/structs/status.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Enum for image status
|
||||
#[derive(Ord, Eq, PartialEq, PartialOrd, Clone, Debug)]
|
||||
pub enum Status {
|
||||
UpdateMajor,
|
||||
UpdateMinor,
|
||||
UpdatePatch,
|
||||
UpdateAvailable,
|
||||
UpToDate,
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
impl Display for Status {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(match &self {
|
||||
Self::UpToDate => "Up to date",
|
||||
Self::UpdateAvailable => "Update available",
|
||||
Self::UpdateMajor => "Major update",
|
||||
Self::UpdateMinor => "Minor update",
|
||||
Self::UpdatePatch => "Patch update",
|
||||
Self::Unknown(_) => "Unknown",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Status {
|
||||
// Converts the Status into an Option<bool> (useful for JSON serialization)
|
||||
pub fn to_option_bool(&self) -> Option<bool> {
|
||||
match &self {
|
||||
Self::UpToDate => Some(false),
|
||||
Self::Unknown(_) => None,
|
||||
_ => Some(true),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Status {
|
||||
fn default() -> Self {
|
||||
Self::Unknown("".to_string())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user