[librsvg: 21/30] style: simplify parsing




commit 9d71fdc5937b2415cc5f01b6ca78321bda412bf4
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Dec 26 15:01:42 2020 +0100

    style: simplify parsing
    
    No need for Option if we have the right default

 src/style.rs   | 8 +++++---
 src/xml/mod.rs | 4 +---
 2 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/src/style.rs b/src/style.rs
index c38e79d7..a0a76dbd 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -17,6 +17,8 @@ pub enum StyleType {
     TextCss,
 }
 
+enum_default!(StyleType, StyleType::TextCss);
+
 impl StyleType {
     fn parse(value: &str) -> Result<StyleType, ValueErrorKind> {
         // https://html.spec.whatwg.org/multipage/semantics.html#the-style-element
@@ -41,11 +43,11 @@ impl StyleType {
 /// the code to use.
 #[derive(Default)]
 pub struct Style {
-    type_: Option<StyleType>,
+    type_: StyleType,
 }
 
 impl Style {
-    pub fn style_type(&self) -> Option<StyleType> {
+    pub fn style_type(&self) -> StyleType {
         self.type_
     }
 }
@@ -54,7 +56,7 @@ impl SetAttributes for Style {
     fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
         for (attr, value) in attrs.iter() {
             if attr.expanded() == expanded_name!("", "type") {
-                self.type_ = Some(StyleType::parse(value).attribute(attr)?);
+                self.type_ = StyleType::parse(value).attribute(attr)?;
             }
         }
 
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index 6c619cc8..884e2997 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -368,9 +368,7 @@ impl XmlState {
         let mut inner = self.inner.borrow_mut();
         let current_node = inner.current_node.as_ref().unwrap();
 
-        let style_type = borrow_element_as!(current_node, Style)
-            .style_type()
-            .unwrap_or(StyleType::TextCss);
+        let style_type = borrow_element_as!(current_node, Style).style_type();
 
         if style_type == StyleType::TextCss {
             let stylesheet_text = current_node


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]