diff --git a/src/picture.rs b/src/picture.rs
@@ -217,22 +217,27 @@ impl LicenseType {
}
pub fn parse(s: &str) -> Result<Option<Self>, ()> {
+ if !LICENSES.contains(&s) {
+ return Err(());
+ }
+
if s == "PD" {
return Ok(None);
} else if s == "CC0" {
return Ok(Some(Self(CreativeCommons::CC0)));
}
- if s.len() < 3 {
- return Err(());
- }
+ 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,
- _ => return Err(())
+ _ => {
+ unreachable!("if s is in LICENSES we should be able to parse the license version")
+ },
};
match &s[..s.len() - 1] {
@@ -312,7 +317,9 @@ impl LicenseType {
)
)
},
- _ => Err(())
+ _ => {
+ unreachable!("if s is in LICENSES we should be able to parse the license-type")
+ },
}
}
}