[librsvg: 5/6] DocumentBuilder.build() - consume self instead of doing acrobatics with Option.take()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 5/6] DocumentBuilder.build() - consume self instead of doing acrobatics with Option.take()
- Date: Fri, 1 Nov 2019 19:07:59 +0000 (UTC)
commit 7bf1391ec56f795cf9c5888b8ae2385c1b498855
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 1 13:03:47 2019 -0600
DocumentBuilder.build() - consume self instead of doing acrobatics with Option.take()
Also, remove the aliasing of self.tree and root - they point to the
same node.
rsvg_internals/src/document.rs | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/rsvg_internals/src/document.rs b/rsvg_internals/src/document.rs
index 8d82de1a..5e6ad958 100644
--- a/rsvg_internals/src/document.rs
+++ b/rsvg_internals/src/document.rs
@@ -327,30 +327,33 @@ impl DocumentBuilder {
}
// FIXME: handle CSS errors
- let _ = self
- .css_rules
- .load_css(&self.resolve_href(s.href.as_ref().unwrap())?);
+ let _ = self.css_rules.load_css(&self.resolve_href(s.href.as_ref().unwrap())?);
}
- match self.tree {
+ let DocumentBuilder { load_options, tree, ids, css_rules, .. } = self;
+
+ match tree {
None => Err(LoadingError::SvgHasNoElements),
- Some(ref mut root) if root.borrow().get_type() == NodeType::Svg => {
- for mut node in root.descendants() {
- node.borrow_mut().set_style(&self.css_rules);
+ Some(mut root) => {
+ if root.borrow().get_type() == NodeType::Svg {
+ for mut node in root.descendants() {
+ node.borrow_mut().set_style(&css_rules);
+ }
+
+ let values = ComputedValues::default();
+ root.cascade(&values);
+
+ Ok(Document {
+ tree: root.clone(),
+ ids: ids,
+ externs: RefCell::new(Resources::new()),
+ images: RefCell::new(Images::new()),
+ load_options: load_options.clone(),
+ })
+ } else {
+ Err(LoadingError::RootElementIsNotSvg)
}
-
- let values = ComputedValues::default();
- root.cascade(&values);
-
- Ok(Document {
- tree: self.tree.take().unwrap(),
- ids: self.ids,
- externs: RefCell::new(Resources::new()),
- images: RefCell::new(Images::new()),
- load_options: self.load_options.clone(),
- })
}
- _ => Err(LoadingError::RootElementIsNotSvg),
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]