[librsvg: 1/2] node: move Display trait impl on NodeData



commit 51af0b1f06563f6add431c396c0f41502c341db6
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Jun 4 16:26:41 2019 +0200

    node: move Display trait impl on NodeData

 rsvg_internals/src/node.rs           | 46 ++++++++++++++++++++++++------------
 rsvg_internals/src/tree_utils/mod.rs |  7 ++++++
 2 files changed, 38 insertions(+), 15 deletions(-)
---
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 908f2701..648a9fbd 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -69,6 +69,22 @@ impl NodeData {
         (&self.node_impl).downcast_ref::<T>()
     }
 
+    pub fn get_type(&self) -> NodeType {
+        self.node_type
+    }
+
+    pub fn element_name(&self) -> &str {
+        self.element_name.as_ref()
+    }
+
+    pub fn get_id(&self) -> Option<&str> {
+        self.id.as_ref().map(String::as_str)
+    }
+
+    pub fn get_class(&self) -> Option<&str> {
+        self.class.as_ref().map(String::as_str)
+    }
+
     pub fn set_atts(&self, node: &RsvgNode, pbag: &PropertyBag<'_>, locale: &Locale) {
         if self.node_impl.overflow_hidden() {
             let mut specified_values = self.specified_values.borrow_mut();
@@ -232,6 +248,17 @@ impl NodeData {
     }
 }
 
+impl fmt::Display for NodeData {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(
+            f,
+            "{:?} id={}",
+            self.get_type(),
+            self.get_id().unwrap_or("None")
+        )
+    }
+}
+
 /// Can obtain computed values from a node
 ///
 /// In our tree of SVG elements (Node in our parlance), each node stores a `ComputedValues` that
@@ -426,19 +453,19 @@ pub enum NodeType {
 
 impl RsvgNode {
     pub fn get_type(&self) -> NodeType {
-        self.borrow().node_type
+        self.borrow().get_type()
     }
 
     pub fn element_name(&self) -> &str {
-        self.borrow().element_name.as_ref()
+        self.borrow().element_name()
     }
 
     pub fn get_id(&self) -> Option<&str> {
-        self.borrow().id.as_ref().map(String::as_str)
+        self.borrow().get_id()
     }
 
     pub fn get_class(&self) -> Option<&str> {
-        self.borrow().class.as_ref().map(String::as_str)
+        self.borrow().get_class()
     }
 
     pub fn get_transform(&self) -> Matrix {
@@ -527,14 +554,3 @@ impl RsvgNode {
         self.borrow().specified_values.borrow().is_overflow()
     }
 }
-
-impl fmt::Display for RsvgNode {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(
-            f,
-            "{:?} id={}",
-            self.get_type(),
-            self.get_id().unwrap_or("None")
-        )
-    }
-}
diff --git a/rsvg_internals/src/tree_utils/mod.rs b/rsvg_internals/src/tree_utils/mod.rs
index e9c92a62..dd6c9c84 100644
--- a/rsvg_internals/src/tree_utils/mod.rs
+++ b/rsvg_internals/src/tree_utils/mod.rs
@@ -1,4 +1,5 @@
 use std::cell::RefCell;
+use std::fmt;
 use std::ops::Deref;
 use std::rc::{Rc, Weak};
 
@@ -48,6 +49,12 @@ impl<T> PartialEq for NodeRef<T> {
     }
 }
 
+impl<T: fmt::Display> fmt::Display for NodeRef<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::Display::fmt(&self.0.data, f)
+    }
+}
+
 pub struct Node<T> {
     parent: Option<NodeWeakRef<T>>,
     first_child: RefCell<Option<NodeRef<T>>>,


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