diff --git a/src/gallery_entry.rs b/src/gallery_entry.rs
@@ -5,6 +5,7 @@ use serde::{
use std::{fmt::{self, Display}, path::PathBuf};
const LICENSES: &[&str] = &[
+ "proprietary",
"PD",
"CC0",
"CC-BY-1",
@@ -43,7 +44,7 @@ pub struct GalleryEntry {
pub file_format: FileFormat,
pub alt: String,
pub caption: Option<String>,
- pub license: Option<LicenseType>,
+ pub license: LicenseType,
pub source: Option<String>,
pub author: String,
pub author_url: Option<String>,
@@ -58,199 +59,210 @@ pub enum FileFormat {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct LicenseType(CreativeCommons);
+pub enum LicenseType {
+ PublicDomain,
+ Cc(CreativeCommons),
+ Proprietary,
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct CreativeCommons(CcInternal);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum CreativeCommons {
+enum CcInternal {
/// Creative Commons (without attribution)
Cc0,
/// Creative Commons Attributions (derivatives allowed)
CcBy {
- version: CreativeCommonsVersion,
+ version: CcVersion,
non_commercial: bool,
share_alike: bool,
},
// The ND (non-derivatives) option excludes the SA (share alike) option
/// Creative Commons Attributions Non-Derivatives
CcByNd {
- version: CreativeCommonsVersion,
+ version: CcVersion,
non_commercial: bool,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-enum CreativeCommonsVersion {
+enum CcVersion {
One,
Two,
Three,
Four,
}
-impl LicenseType {
+impl CreativeCommons {
pub const fn url(&self) -> &'static str {
match self.0 {
// CC0
- CreativeCommons::Cc0 => {
+ CcInternal::Cc0 => {
"https://creativecommons.org/publicdomain/zero/1.0/"
},
// CC-BY-1
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcBy {
+ version: CcVersion::One,
non_commercial: false,
share_alike: false,
} => "http://creativecommons.org/licenses/by/1.0/",
// CC-BY-2
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcBy {
+ version: CcVersion::Two,
non_commercial: false,
share_alike: false,
} => "http://creativecommons.org/licenses/by/2.0/",
// CC-BY-3
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcBy {
+ version: CcVersion::Three,
non_commercial: false,
share_alike: false,
} => "http://creativecommons.org/licenses/by/3.0/",
// CC-BY-4
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcBy {
+ version: CcVersion::Four,
non_commercial: false,
share_alike: false,
} => "http://creativecommons.org/licenses/by/4.0/",
// CC-BY-SA-1
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcBy {
+ version: CcVersion::One,
non_commercial: false,
share_alike: true,
} => "http://creativecommons.org/licenses/by-sa/1.0/",
// CC-BY-SA-2
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcBy {
+ version: CcVersion::Two,
non_commercial: false,
share_alike: true,
} => "http://creativecommons.org/licenses/by-sa/2.0/",
// CC-BY-SA-3
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcBy {
+ version: CcVersion::Three,
non_commercial: false,
share_alike: true,
} => "http://creativecommons.org/licenses/by-sa/3.0/",
// CC-BY-SA-4
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcBy {
+ version: CcVersion::Four,
non_commercial: false,
share_alike: true,
} => "http://creativecommons.org/licenses/by-sa/4.0/",
// CC-BY-NC-1
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcBy {
+ version: CcVersion::One,
non_commercial: true,
share_alike: false,
} => "http://creativecommons.org/licenses/by-nc/1.0/",
// CC-BY-NC-2
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcBy {
+ version: CcVersion::Two,
non_commercial: true,
share_alike: false,
} => "http://creativecommons.org/licenses/by-nc/2.0/",
// CC-BY-NC-3
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcBy {
+ version: CcVersion::Three,
non_commercial: true,
share_alike: false,
} => "http://creativecommons.org/licenses/by-nc/3.0/",
// CC-BY-NC-4
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcBy {
+ version: CcVersion::Four,
non_commercial: true,
share_alike: false,
} => "http://creativecommons.org/licenses/by-nc/4.0/",
// CC-BY-NC-SA-1
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcBy {
+ version: CcVersion::One,
non_commercial: true,
share_alike: true,
} => "http://creativecommons.org/licenses/by-nc-sa/1.0/",
// CC-BY-NC-SA-2
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcBy {
+ version: CcVersion::Two,
non_commercial: true,
share_alike: true,
} => "http://creativecommons.org/licenses/by-nc-sa/2.0/",
// CC-BY-NC-SA-3
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcBy {
+ version: CcVersion::Three,
non_commercial: true,
share_alike: true,
} => "http://creativecommons.org/licenses/by-nc-sa/3.0/",
// CC-BY-NC-SA-4
- CreativeCommons::CcBy {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcBy {
+ version: CcVersion::Four,
non_commercial: true,
share_alike: true,
} => "http://creativecommons.org/licenses/by-nc-sa/4.0/",
// CC-BY-ND-1
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcByNd {
+ version: CcVersion::One,
non_commercial: false,
} => "http://creativecommons.org/licenses/by-nd/1.0/",
// CC-BY-ND-2
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcByNd {
+ version: CcVersion::Two,
non_commercial: false,
} => "http://creativecommons.org/licenses/by-nd/2.0/",
// CC-BY-ND-3
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcByNd {
+ version: CcVersion::Three,
non_commercial: false,
} => "http://creativecommons.org/licenses/by-nd/3.0/",
// CC-BY-ND-4
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcByNd {
+ version: CcVersion::Four,
non_commercial: false,
} => "http://creativecommons.org/licenses/by-nd/4.0/",
// CC-BY-NC-ND-1
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::One,
+ CcInternal::CcByNd {
+ version: CcVersion::One,
non_commercial: true,
} => "http://creativecommons.org/licenses/by-nc-nd/1.0/",
// CC-BY-NC-ND-2
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Two,
+ CcInternal::CcByNd {
+ version: CcVersion::Two,
non_commercial: true,
} => "http://creativecommons.org/licenses/by-nc-nd/2.0/",
// CC-BY-NC-ND-3
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Three,
+ CcInternal::CcByNd {
+ version: CcVersion::Three,
non_commercial: true,
} => "http://creativecommons.org/licenses/by-nc-nd/3.0/",
// CC-BY-NC-ND-4
- CreativeCommons::CcByNd {
- version: CreativeCommonsVersion::Four,
+ CcInternal::CcByNd {
+ version: CcVersion::Four,
non_commercial: true,
} => "http://creativecommons.org/licenses/by-nc-nd/4.0/",
}
}
+}
- pub fn parse(s: &str) -> Result<Option<Self>, ()> {
+impl LicenseType {
+ pub fn parse(s: &str) -> Result<Self, ()> {
if !LICENSES.contains(&s) {
return Err(());
}
- if s == "PD" {
- return Ok(None);
+ if s == "proprietary" {
+ return Ok(Self::Proprietary);
+ } else if s == "PD" {
+ return Ok(Self::PublicDomain);
} else if s == "CC0" {
- return Ok(Some(Self(CreativeCommons::Cc0)));
+ return Ok(Self::Cc(CreativeCommons(CcInternal::Cc0)));
}
assert!(s.len() >= 3,
"if s is in LICENSES it should contain at least 3 chars");
let version = match &s[s.len() - 1..] {
- "1" => CreativeCommonsVersion::One,
- "2" => CreativeCommonsVersion::Two,
- "3" => CreativeCommonsVersion::Three,
- "4" => CreativeCommonsVersion::Four,
+ "1" => CcVersion::One,
+ "2" => CcVersion::Two,
+ "3" => CcVersion::Three,
+ "4" => CcVersion::Four,
_ => {
unreachable!("if s is in LICENSES we should be able to parse the license version")
},
@@ -258,80 +270,44 @@ impl LicenseType {
match &s[..s.len() - 1] {
"CC-BY-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcBy {
- version,
- non_commercial: false,
- share_alike: false,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcBy {
+ version,
+ non_commercial: false,
+ share_alike: false,
+ })))
},
"CC-BY-NC-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcBy {
- version,
- non_commercial: true,
- share_alike: false,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcBy {
+ version,
+ non_commercial: true,
+ share_alike: false,
+ })))
},
"CC-BY-SA-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcBy {
- version,
- non_commercial: false,
- share_alike: true,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcBy {
+ version,
+ non_commercial: false,
+ share_alike: true,
+ })))
},
"CC-BY-NC-SA-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcBy {
- version,
- non_commercial: true,
- share_alike: true,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcBy {
+ version,
+ non_commercial: true,
+ share_alike: true,
+ })))
},
"CC-BY-ND-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcByNd {
- version,
- non_commercial: false,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcByNd {
+ version,
+ non_commercial: false,
+ })))
},
"CC-BY-NC-ND-" => {
- Ok(
- Some(
- Self(
- CreativeCommons::CcByNd {
- version,
- non_commercial: true,
- }
- )
- )
- )
+ Ok(Self::Cc(CreativeCommons(CcInternal::CcByNd {
+ version,
+ non_commercial: true,
+ })))
},
_ => {
unreachable!("if s is in LICENSES we should be able to parse the license-type")
@@ -408,11 +384,11 @@ impl<'de> Deserialize<'de> for GalleryEntry {
}
}
-impl Display for LicenseType {
+impl Display for CreativeCommons {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self.0 {
- CreativeCommons::Cc0 => write!(f, "CC0"),
- CreativeCommons::CcBy { version, non_commercial, share_alike } => {
+ CcInternal::Cc0 => write!(f, "CC0"),
+ CcInternal::CcBy { version, non_commercial, share_alike } => {
write!(f, "CC-BY")?;
if non_commercial {
write!(f, "-NC")?;
@@ -422,7 +398,7 @@ impl Display for LicenseType {
}
write!(f, " {version}")
},
- CreativeCommons::CcByNd { version, non_commercial } => {
+ CcInternal::CcByNd { version, non_commercial } => {
write!(f, "CC-BY")?;
if non_commercial {
write!(f, "-NC")?;
@@ -433,13 +409,13 @@ impl Display for LicenseType {
}
}
-impl Display for CreativeCommonsVersion {
+impl Display for CcVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
- CreativeCommonsVersion::One => write!(f, "1.0"),
- CreativeCommonsVersion::Two => write!(f, "2.0"),
- CreativeCommonsVersion::Three => write!(f, "3.0"),
- CreativeCommonsVersion::Four => write!(f, "4.0"),
+ CcVersion::One => write!(f, "1.0"),
+ CcVersion::Two => write!(f, "2.0"),
+ CcVersion::Three => write!(f, "3.0"),
+ CcVersion::Four => write!(f, "4.0"),
}
}
}