implement deserialize

This commit is contained in:
Sam Denty 2021-02-02 17:30:35 +00:00
parent 919d5e2cb6
commit b93aa199ef
No known key found for this signature in database
GPG key ID: F3E9308D4A43BC0E
3 changed files with 18 additions and 4 deletions

2
Cargo.lock generated
View file

@ -1527,7 +1527,7 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7"
[[package]]
name = "site_icons"
version = "0.1.3"
version = "0.1.4"
dependencies = [
"byteorder",
"clap",

View file

@ -1,6 +1,6 @@
[package]
name = "site_icons"
version = "0.1.3"
version = "0.1.4"
authors = ["Sam Denty <sam@samdenty.com>"]
edition = "2018"
license = "GPL-3.0"

View file

@ -3,10 +3,11 @@ use serde::Serialize;
use std::{
cmp::Ordering,
fmt::{self, Display},
str::FromStr,
};
use url::Url;
#[derive(Debug, Serialize, Clone, PartialOrd, PartialEq, Ord, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialOrd, PartialEq, Ord, Eq)]
pub enum IconKind {
SiteLogo,
SiteFavicon,
@ -23,7 +24,20 @@ impl Display for IconKind {
}
}
#[derive(Debug, Serialize, PartialEq, Eq)]
impl FromStr for IconKind {
type Err = String;
fn from_str(kind: &str) -> Result<Self, Self::Err> {
match kind {
"site_logo" => Ok(IconKind::SiteLogo),
"app_icon" => Ok(IconKind::AppIcon),
"site_favicon" => Ok(IconKind::SiteFavicon),
_ => Err("unknown icon kind!".into()),
}
}
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Icon {
pub url: Url,
#[serde(with = "serde_with::rust::display_fromstr")]