This repository has been archived on 2025-01-30. You can view files and clone it, but cannot push or open issues or pull requests.
site_icons/src/icon.rs

46 lines
927 B
Rust
Raw Normal View History

2021-01-29 12:23:15 +00:00
use super::IconInfo;
use serde::Serialize;
use std::{
cmp::Ordering,
fmt::{self, Display},
};
use url::Url;
#[derive(Debug, Serialize, Clone, PartialOrd, PartialEq, Ord, Eq)]
pub enum IconKind {
SiteLogo,
SiteFavicon,
AppIcon,
}
impl Display for IconKind {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(match self {
IconKind::SiteLogo => "site_logo",
IconKind::AppIcon => "app_icon",
IconKind::SiteFavicon => "site_favicon",
})
}
}
#[derive(Debug, Serialize, PartialEq, Eq)]
pub struct Icon {
pub url: Url,
#[serde(with = "serde_with::rust::display_fromstr")]
pub kind: IconKind,
#[serde(flatten)]
pub info: IconInfo,
}
impl Ord for Icon {
fn cmp(&self, other: &Self) -> Ordering {
self.info.cmp(&other.info)
}
}
impl PartialOrd for Icon {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}