tikz-gallery-generator

Custum build of stapix for tikz.pablopie.xyz

Commit
f927aa34511ed57ba4557e617cc0265287d6cad1
Parent
d671c683995e41b31bd16820a44e88ef548779a4
Author
Pablo <pablo-escobar@riseup.net>
Date

Replaced buisness logic with asserts

Simplified the business logic a bit using asserts

Diffstat

1 file changed, 12 insertions, 5 deletions

Status File Name N° Changes Insertions Deletions
Modified src/picture.rs 17 12 5
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")
+            },
         }
     }
 }