[librsvg: 3/6] parse: add blanket implementation for parsing Option
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/6] parse: add blanket implementation for parsing Option
- Date: Tue, 22 Dec 2020 17:39:49 +0000 (UTC)
commit 2ab0c9e21d927d75b7d978fb381867fd7f559072
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Dec 20 11:19:20 2020 +0100
parse: add blanket implementation for parsing Option
src/filters/blend.rs | 4 +---
src/filters/composite.rs | 2 +-
src/filters/displacement_map.rs | 4 +---
src/filters/lighting.rs | 2 +-
src/filters/mod.rs | 10 +++++-----
src/gradient.rs | 28 +++++++++++++---------------
src/parsers.rs | 6 ++++++
src/pattern.rs | 18 +++++++++---------
src/shapes.rs | 4 ++--
src/structure.rs | 16 ++++++++--------
src/text.rs | 12 ++++++------
11 files changed, 53 insertions(+), 53 deletions(-)
---
diff --git a/src/filters/blend.rs b/src/filters/blend.rs
index a993533b..eda17b2b 100755
--- a/src/filters/blend.rs
+++ b/src/filters/blend.rs
@@ -58,9 +58,7 @@ impl SetAttributes for FeBlend {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "in2") => {
- self.in2 = Some(attr.parse(value)?);
- }
+ expanded_name!("", "in2") => self.in2 = attr.parse(value)?,
expanded_name!("", "mode") => self.mode = attr.parse(value)?,
_ => (),
}
diff --git a/src/filters/composite.rs b/src/filters/composite.rs
index 7428cd6e..d256869b 100644
--- a/src/filters/composite.rs
+++ b/src/filters/composite.rs
@@ -56,7 +56,7 @@ impl SetAttributes for FeComposite {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "in2") => self.in2 = Some(attr.parse(value)?),
+ expanded_name!("", "in2") => self.in2 = attr.parse(value)?,
expanded_name!("", "operator") => self.operator = attr.parse(value)?,
expanded_name!("", "k1") => self.k1 = attr.parse(value)?,
expanded_name!("", "k2") => self.k2 = attr.parse(value)?,
diff --git a/src/filters/displacement_map.rs b/src/filters/displacement_map.rs
index 2e03b58e..3dbabbcb 100644
--- a/src/filters/displacement_map.rs
+++ b/src/filters/displacement_map.rs
@@ -51,13 +51,11 @@ impl SetAttributes for FeDisplacementMap {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "in2") => self.in2 = Some(attr.parse(value)?),
+ expanded_name!("", "in2") => self.in2 = attr.parse(value)?,
expanded_name!("", "scale") => self.scale = attr.parse(value)?,
-
expanded_name!("", "xChannelSelector") => {
self.x_channel_selector = attr.parse(value)?
}
-
expanded_name!("", "yChannelSelector") => {
self.y_channel_selector = attr.parse(value)?
}
diff --git a/src/filters/lighting.rs b/src/filters/lighting.rs
index fa269c6e..946ff75c 100644
--- a/src/filters/lighting.rs
+++ b/src/filters/lighting.rs
@@ -220,7 +220,7 @@ impl SetAttributes for FeSpotLight {
}
expanded_name!("", "limitingConeAngle") => {
- self.limiting_cone_angle = Some(attr.parse(value)?)
+ self.limiting_cone_angle = attr.parse(value)?
}
_ => (),
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index 33b23ed6..3a8c6c93 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -180,11 +180,11 @@ impl SetAttributes for Primitive {
fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "x") => self.x = attr.parse(value).map(Some)?,
- expanded_name!("", "y") => self.y = attr.parse(value).map(Some)?,
- expanded_name!("", "width") => self.width = attr.parse(value).map(Some)?,
- expanded_name!("", "height") => self.height = attr.parse(value).map(Some)?,
- expanded_name!("", "result") => self.result = attr.parse(value).map(Some)?,
+ expanded_name!("", "x") => self.x = attr.parse(value)?,
+ expanded_name!("", "y") => self.y = attr.parse(value)?,
+ expanded_name!("", "width") => self.width = attr.parse(value)?,
+ expanded_name!("", "height") => self.height = attr.parse(value)?,
+ expanded_name!("", "result") => self.result = attr.parse(value)?,
_ => (),
}
}
diff --git a/src/gradient.rs b/src/gradient.rs
index 69298c05..a6cc2b6a 100644
--- a/src/gradient.rs
+++ b/src/gradient.rs
@@ -544,11 +544,9 @@ impl SetAttributes for Common {
fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "gradientUnits") => self.units = Some(attr.parse(value)?),
- expanded_name!("", "gradientTransform") => {
- self.transform = Some(attr.parse(value)?)
- }
- expanded_name!("", "spreadMethod") => self.spread = Some(attr.parse(value)?),
+ expanded_name!("", "gradientUnits") => self.units = attr.parse(value)?,
+ expanded_name!("", "gradientTransform") => self.transform = attr.parse(value)?,
+ expanded_name!("", "spreadMethod") => self.spread = attr.parse(value)?,
ref a if is_href(a) => {
set_href(
a,
@@ -570,10 +568,10 @@ impl SetAttributes for LinearGradient {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "x1") => self.x1 = Some(attr.parse(value)?),
- expanded_name!("", "y1") => self.y1 = Some(attr.parse(value)?),
- expanded_name!("", "x2") => self.x2 = Some(attr.parse(value)?),
- expanded_name!("", "y2") => self.y2 = Some(attr.parse(value)?),
+ expanded_name!("", "x1") => self.x1 = attr.parse(value)?,
+ expanded_name!("", "y1") => self.y1 = attr.parse(value)?,
+ expanded_name!("", "x2") => self.x2 = attr.parse(value)?,
+ expanded_name!("", "y2") => self.y2 = attr.parse(value)?,
_ => (),
}
@@ -673,14 +671,14 @@ impl SetAttributes for RadialGradient {
let attr_expanded = attr.expanded();
if attr_expanded == expanded_name_fr {
- self.fr = Some(attr.parse(value)?);
+ self.fr = attr.parse(value)?;
} else {
match attr_expanded {
- expanded_name!("", "cx") => self.cx = Some(attr.parse(value)?),
- expanded_name!("", "cy") => self.cy = Some(attr.parse(value)?),
- expanded_name!("", "r") => self.r = Some(attr.parse(value)?),
- expanded_name!("", "fx") => self.fx = Some(attr.parse(value)?),
- expanded_name!("", "fy") => self.fy = Some(attr.parse(value)?),
+ expanded_name!("", "cx") => self.cx = attr.parse(value)?,
+ expanded_name!("", "cy") => self.cy = attr.parse(value)?,
+ expanded_name!("", "r") => self.r = attr.parse(value)?,
+ expanded_name!("", "fx") => self.fx = attr.parse(value)?,
+ expanded_name!("", "fy") => self.fy = attr.parse(value)?,
_ => (),
}
diff --git a/src/parsers.rs b/src/parsers.rs
index 14d558ac..3a63bbf1 100644
--- a/src/parsers.rs
+++ b/src/parsers.rs
@@ -78,6 +78,12 @@ impl<T: Parse> ParseValue<T> for QualName {
}
}
+impl<T: Parse> Parse for Option<T> {
+ fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
+ T::parse(parser).map(Some)
+ }
+}
+
impl Parse for f64 {
fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<Self, ParseError<'i>> {
let loc = parser.current_source_location();
diff --git a/src/pattern.rs b/src/pattern.rs
index 598d4cba..e9511bfc 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -126,16 +126,16 @@ impl SetAttributes for Pattern {
fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "patternUnits") => self.common.units = Some(attr.parse(value)?),
+ expanded_name!("", "patternUnits") => self.common.units = attr.parse(value)?,
expanded_name!("", "patternContentUnits") => {
- self.common.content_units = Some(attr.parse(value)?)
+ self.common.content_units = attr.parse(value)?
}
- expanded_name!("", "viewBox") => self.common.vbox = Some(Some(attr.parse(value)?)),
+ expanded_name!("", "viewBox") => self.common.vbox = attr.parse(value)?,
expanded_name!("", "preserveAspectRatio") => {
- self.common.preserve_aspect_ratio = Some(attr.parse(value)?)
+ self.common.preserve_aspect_ratio = attr.parse(value)?
}
expanded_name!("", "patternTransform") => {
- self.common.transform = Some(attr.parse(value)?)
+ self.common.transform = attr.parse(value)?
}
ref a if is_href(a) => {
set_href(
@@ -144,10 +144,10 @@ impl SetAttributes for Pattern {
NodeId::parse(value).attribute(attr.clone())?,
);
}
- expanded_name!("", "x") => self.common.x = Some(attr.parse(value)?),
- expanded_name!("", "y") => self.common.y = Some(attr.parse(value)?),
- expanded_name!("", "width") => self.common.width = Some(attr.parse(value)?),
- expanded_name!("", "height") => self.common.height = Some(attr.parse(value)?),
+ expanded_name!("", "x") => self.common.x = attr.parse(value)?,
+ expanded_name!("", "y") => self.common.y = attr.parse(value)?,
+ expanded_name!("", "width") => self.common.width = attr.parse(value)?,
+ expanded_name!("", "height") => self.common.height = attr.parse(value)?,
_ => (),
}
}
diff --git a/src/shapes.rs b/src/shapes.rs
index 90fd522a..a9721003 100644
--- a/src/shapes.rs
+++ b/src/shapes.rs
@@ -319,8 +319,8 @@ impl SetAttributes for Rect {
expanded_name!("", "y") => self.y = attr.parse(value)?,
expanded_name!("", "width") => self.width = attr.parse(value)?,
expanded_name!("", "height") => self.height = attr.parse(value)?,
- expanded_name!("", "rx") => self.rx = attr.parse(value).map(Some)?,
- expanded_name!("", "ry") => self.ry = attr.parse(value).map(Some)?,
+ expanded_name!("", "rx") => self.rx = attr.parse(value)?,
+ expanded_name!("", "ry") => self.ry = attr.parse(value)?,
_ => (),
}
}
diff --git a/src/structure.rs b/src/structure.rs
index 73b6e99f..6706f220 100644
--- a/src/structure.rs
+++ b/src/structure.rs
@@ -210,11 +210,11 @@ impl SetAttributes for Svg {
expanded_name!("", "preserveAspectRatio") => {
self.preserve_aspect_ratio = attr.parse(value)?
}
- expanded_name!("", "x") => self.x = Some(attr.parse(value)?),
- expanded_name!("", "y") => self.y = Some(attr.parse(value)?),
- expanded_name!("", "width") => self.width = Some(attr.parse(value)?),
- expanded_name!("", "height") => self.height = Some(attr.parse(value)?),
- expanded_name!("", "viewBox") => self.vbox = attr.parse(value).map(Some)?,
+ expanded_name!("", "x") => self.x = attr.parse(value)?,
+ expanded_name!("", "y") => self.y = attr.parse(value)?,
+ expanded_name!("", "width") => self.width = attr.parse(value)?,
+ expanded_name!("", "height") => self.height = attr.parse(value)?,
+ expanded_name!("", "viewBox") => self.vbox = attr.parse(value)?,
_ => (),
}
}
@@ -284,8 +284,8 @@ impl SetAttributes for Use {
),
expanded_name!("", "x") => self.x = attr.parse(value)?,
expanded_name!("", "y") => self.y = attr.parse(value)?,
- expanded_name!("", "width") => self.width = attr.parse(value).map(Some)?,
- expanded_name!("", "height") => self.height = attr.parse(value).map(Some)?,
+ expanded_name!("", "width") => self.width = attr.parse(value)?,
+ expanded_name!("", "height") => self.height = attr.parse(value)?,
_ => (),
}
}
@@ -330,7 +330,7 @@ impl SetAttributes for Symbol {
expanded_name!("", "preserveAspectRatio") => {
self.preserve_aspect_ratio = attr.parse(value)?
}
- expanded_name!("", "viewBox") => self.vbox = attr.parse(value).map(Some)?,
+ expanded_name!("", "viewBox") => self.vbox = attr.parse(value)?,
_ => (),
}
}
diff --git a/src/text.rs b/src/text.rs
index ee1ad0d4..4aef2455 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -465,8 +465,8 @@ impl SetAttributes for Text {
match attr.expanded() {
expanded_name!("", "x") => self.x = attr.parse(value)?,
expanded_name!("", "y") => self.y = attr.parse(value)?,
- expanded_name!("", "dx") => self.dx = attr.parse(value).map(Some)?,
- expanded_name!("", "dy") => self.dy = attr.parse(value).map(Some)?,
+ expanded_name!("", "dx") => self.dx = attr.parse(value)?,
+ expanded_name!("", "dy") => self.dy = attr.parse(value)?,
_ => (),
}
}
@@ -642,10 +642,10 @@ impl SetAttributes for TSpan {
fn set_attributes(&mut self, attrs: &Attributes) -> ElementResult {
for (attr, value) in attrs.iter() {
match attr.expanded() {
- expanded_name!("", "x") => self.x = attr.parse(value).map(Some)?,
- expanded_name!("", "y") => self.y = attr.parse(value).map(Some)?,
- expanded_name!("", "dx") => self.dx = attr.parse(value).map(Some)?,
- expanded_name!("", "dy") => self.dy = attr.parse(value).map(Some)?,
+ expanded_name!("", "x") => self.x = attr.parse(value)?,
+ expanded_name!("", "y") => self.y = attr.parse(value)?,
+ expanded_name!("", "dx") => self.dx = attr.parse(value)?,
+ expanded_name!("", "dy") => self.dy = attr.parse(value)?,
_ => (),
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]