implement deserialize
This commit is contained in:
parent
919d5e2cb6
commit
b93aa199ef
3 changed files with 18 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1527,7 +1527,7 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "site_icons"
|
name = "site_icons"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
18
src/icon.rs
18
src/icon.rs
|
@ -3,10 +3,11 @@ use serde::Serialize;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
|
str::FromStr,
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone, PartialOrd, PartialEq, Ord, Eq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialOrd, PartialEq, Ord, Eq)]
|
||||||
pub enum IconKind {
|
pub enum IconKind {
|
||||||
SiteLogo,
|
SiteLogo,
|
||||||
SiteFavicon,
|
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 struct Icon {
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
#[serde(with = "serde_with::rust::display_fromstr")]
|
#[serde(with = "serde_with::rust::display_fromstr")]
|
||||||
|
|
Reference in a new issue