[librsvg: 3/19] Express `Result.and_then(|x| Ok(y))` as `map(|x| y)`




commit 13d346a405b0d8a907e32a4d5255efe427294d69
Author: Sven Neumann <sven svenfoo org>
Date:   Thu Aug 20 19:50:20 2020 +0200

    Express `Result.and_then(|x| Ok(y))` as `map(|x| y)`
    
    See https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map

 rsvg_internals/src/drawing_ctx.rs     | 33 +++++++++++++--------------------
 rsvg_internals/src/element.rs         |  9 +++------
 rsvg_internals/src/filters/context.rs |  3 +--
 rsvg_internals/src/font_props.rs      |  4 ++--
 rsvg_internals/src/pattern.rs         |  2 +-
 rsvg_internals/src/text.rs            |  8 +++-----
 6 files changed, 23 insertions(+), 36 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index c105b257d..4e61f11ce 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -313,7 +313,7 @@ impl DrawingCtx {
                 }
                 None // so that the following and_then() won't run
             })
-            .and_then(|t| {
+            .map(|t| {
                 self.cr.transform(t.into());
 
                 if let Some(vbox) = vbox {
@@ -321,10 +321,9 @@ impl DrawingCtx {
                         cr.rectangle(vbox.0.x0, vbox.0.y0, vbox.0.width(), vbox.0.height());
                         cr.clip();
                     }
-
-                    Some(self.push_view_box(vbox.0.width(), vbox.0.height()))
+                    self.push_view_box(vbox.0.width(), vbox.0.height())
                 } else {
-                    Some(self.get_view_params())
+                    self.get_view_params()
                 }
             })
     }
@@ -360,11 +359,9 @@ impl DrawingCtx {
 
                 res
             })
-            .and_then(|_bbox|
-                         // Clipping paths do not contribute to bounding boxes (they should,
-                         // but we need Real Computational Geometry(tm), so ignore the
-                         // bbox from the clip path.
-                         Ok(()))
+            // Clipping paths do not contribute to bounding boxes (they should, but we
+            // need Real Computational Geometry(tm), so ignore the bbox from the clip path.
+            .map(|_bbox| ())
         } else {
             Ok(())
         }
@@ -606,12 +603,11 @@ impl DrawingCtx {
                                             &bbox,
                                             acquired_nodes,
                                         )
-                                        .and_then(|mask_surf| {
+                                        .map(|mask_surf| {
                                             if let Some(surf) = mask_surf {
                                                 dc.cr.set_matrix(affines.compositing.into());
                                                 dc.cr.mask_surface(&surf, 0.0, 0.0);
                                             }
-                                            Ok(())
                                         })
                                         .map(|_: ()| bbox)
                                     });
@@ -955,7 +951,7 @@ impl DrawingCtx {
                 &bbox,
                 current_color,
             )
-            .and_then(|had_paint_server| {
+            .map(|had_paint_server| {
                 if had_paint_server {
                     if values.stroke().0 == PaintServer::None {
                         cr.fill();
@@ -963,8 +959,6 @@ impl DrawingCtx {
                         cr.fill_preserve();
                     }
                 }
-
-                Ok(())
             })
             .and_then(|_| {
                 self.set_source_paint_server(
@@ -974,11 +968,10 @@ impl DrawingCtx {
                     &bbox,
                     current_color,
                 )
-                .and_then(|had_paint_server| {
+                .map(|had_paint_server| {
                     if had_paint_server {
                         cr.stroke();
                     }
-                    Ok(())
                 })
             });
 
@@ -986,7 +979,7 @@ impl DrawingCtx {
         // we leave it around from computing the bounding box
         cr.new_path();
 
-        res.and_then(|_: ()| Ok(bbox))
+        res.map(|_: ()| bbox)
     }
 
     pub fn draw_path(
@@ -1300,14 +1293,14 @@ fn get_clip_in_user_and_object_space(
                 .ok()
                 .filter(|a| is_element_of_type!(*a.get(), ClipPath))
         })
-        .and_then(|acquired| {
+        .map(|acquired| {
             let clip_node = acquired.get().clone();
 
             let units = borrow_element_as!(clip_node, ClipPath).get_units();
 
             match units {
-                CoordUnits::UserSpaceOnUse => Some((Some(clip_node), None)),
-                CoordUnits::ObjectBoundingBox => Some((None, Some(clip_node))),
+                CoordUnits::UserSpaceOnUse => (Some(clip_node), None),
+                CoordUnits::ObjectBoundingBox => (None, Some(clip_node)),
             }
         })
         .unwrap_or((None, None))
diff --git a/rsvg_internals/src/element.rs b/rsvg_internals/src/element.rs
index bffd534b3..a90914b1c 100644
--- a/rsvg_internals/src/element.rs
+++ b/rsvg_internals/src/element.rs
@@ -155,12 +155,9 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
                 expanded_name!("", "transform") => {
-                    return Transform::parse_str(value)
-                        .attribute(attr)
-                        .and_then(|affine| {
-                            self.transform = affine;
-                            Ok(())
-                        });
+                    return Transform::parse_str(value).attribute(attr).map(|affine| {
+                        self.transform = affine;
+                    });
                 }
                 _ => (),
             }
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index a7b63250d..b9440cf04 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -291,11 +291,10 @@ impl FilterContext {
                     &self.node_bbox,
                     self.computed_from_node_being_filtered.color().0,
                 )
-                .and_then(|had_paint_server| {
+                .map(|had_paint_server| {
                     if had_paint_server {
                         cr.paint();
                     }
-                    Ok(())
                 });
 
             draw_ctx.set_cairo_context(&cr_save);
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index f4d13923d..6cae0bf92 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -238,7 +238,7 @@ impl Parse for FontSize {
     fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<FontSize, ParseError<'i>> {
         parser
             .try_parse(|p| Length::<Both>::parse(p))
-            .and_then(|l| Ok(FontSize::Value(l)))
+            .map(FontSize::Value)
             .or_else(|_| {
                 Ok(parse_identifiers!(
                     parser,
@@ -377,7 +377,7 @@ impl Parse for LetterSpacing {
     fn parse<'i>(parser: &mut Parser<'i, '_>) -> Result<LetterSpacing, ParseError<'i>> {
         parser
             .try_parse(|p| Length::<Horizontal>::parse(p))
-            .and_then(|l| Ok(LetterSpacing::Value(l)))
+            .map(LetterSpacing::Value)
             .or_else(|_| {
                 Ok(parse_identifiers!(
                     parser,
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 9ce96233e..4cb4cec59 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -378,7 +378,7 @@ impl AsPaintSource for ResolvedPattern {
         pattern.set_filter(cairo::Filter::Best);
         cr_save.set_source(&pattern);
 
-        res.and_then(|_| Ok(true))
+        res.map(|_| true)
     }
 }
 
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index cca06ddd8..07d1ababb 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -308,12 +308,11 @@ impl PositionedSpan {
                     &bbox,
                     current_color,
                 )
-                .and_then(|had_paint_server| {
+                .map(|had_paint_server| {
                     if had_paint_server {
                         pangocairo::functions::update_layout(&cr, &self.layout);
                         pangocairo::functions::show_layout(&cr, &self.layout);
                     };
-                    Ok(())
                 })
             } else {
                 Ok(())
@@ -330,11 +329,10 @@ impl PositionedSpan {
                         &bbox,
                         current_color,
                     )
-                    .and_then(|had_paint_server| {
+                    .map(|had_paint_server| {
                         if had_paint_server {
                             need_layout_path = true;
                         }
-                        Ok(())
                     })
                 } else {
                     Ok(())
@@ -356,7 +354,7 @@ impl PositionedSpan {
                 }
             }
 
-            res.and_then(|_: ()| Ok(bbox))
+            res.map(|_: ()| bbox)
         })
     }
 


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