[librsvg: 1/4] Use matches! macro as suggested by clippy
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/4] Use matches! macro as suggested by clippy
- Date: Fri, 16 Oct 2020 15:32:59 +0000 (UTC)
commit b48152d863fa6a0ab200f0970b4758be425da66f
Author: Sven Neumann <sven svenfoo org>
Date: Thu Oct 15 19:57:45 2020 +0200
Use matches! macro as suggested by clippy
rsvg_internals/src/aspect_ratio.rs | 12 ++++++------
rsvg_internals/src/drawing_ctx.rs | 6 ++----
rsvg_internals/src/href.rs | 9 +++++----
rsvg_internals/src/node.rs | 13 ++++---------
rsvg_internals/src/pattern.rs | 6 ++----
rsvg_internals/src/properties.rs | 6 ++----
rsvg_internals/src/property_defs.rs | 6 ++----
7 files changed, 23 insertions(+), 35 deletions(-)
---
diff --git a/rsvg_internals/src/aspect_ratio.rs b/rsvg_internals/src/aspect_ratio.rs
index 3dccfd98..ac02c6dc 100644
--- a/rsvg_internals/src/aspect_ratio.rs
+++ b/rsvg_internals/src/aspect_ratio.rs
@@ -20,6 +20,8 @@
//! [`AspectRatio`]: struct.AspectRatio.html
//! [spec]: https://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute
+use cssparser::{BasicParseError, Parser};
+use matches::matches;
use std::ops::Deref;
use crate::error::*;
@@ -27,7 +29,6 @@ use crate::parsers::Parse;
use crate::rect::Rect;
use crate::transform::Transform;
use crate::viewbox::ViewBox;
-use cssparser::{BasicParseError, Parser};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct AspectRatio {
@@ -113,14 +114,13 @@ impl Align1D {
impl AspectRatio {
pub fn is_slice(&self) -> bool {
- match self.align {
+ matches!(
+ self.align,
Some(Align {
fit: FitMode::Slice,
..
- }) => true,
-
- _ => false,
- }
+ })
+ )
}
pub fn compute(&self, vbox: &ViewBox, viewport: &Rect) -> Rect {
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index f6436995..d8a95ce7 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -1,6 +1,7 @@
//! The main context structure which drives the drawing process.
use float_cmp::approx_eq;
+use matches::matches;
use once_cell::sync::Lazy;
use pango::FontMapExt;
use regex::{Captures, Regex};
@@ -1914,10 +1915,7 @@ fn compute_text_box(
// FIXME: should the pango crate provide this like PANGO_GRAVITY_IS_VERTICAL() ?
fn gravity_is_vertical(gravity: pango::Gravity) -> bool {
- match gravity {
- pango::Gravity::East | pango::Gravity::West => true,
- _ => false,
- }
+ matches!(gravity, pango::Gravity::East | pango::Gravity::West)
}
/// escape quotes and backslashes with backslash
diff --git a/rsvg_internals/src/href.rs b/rsvg_internals/src/href.rs
index 1ad294bd..b2a802cf 100644
--- a/rsvg_internals/src/href.rs
+++ b/rsvg_internals/src/href.rs
@@ -8,6 +8,7 @@
//! other. We implement that logic in this module.
use markup5ever::{expanded_name, local_name, namespace_url, ns, ExpandedName};
+use matches::matches;
/// Returns whether the attribute is either of `xlink:href` or `href`.
///
@@ -32,10 +33,10 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns, ExpandedName};
/// }
/// ```
pub fn is_href(name: &ExpandedName) -> bool {
- match *name {
- expanded_name!(xlink "href") | expanded_name!("", "href") => true,
- _ => false,
- }
+ matches!(
+ *name,
+ expanded_name!(xlink "href") | expanded_name!("", "href")
+ )
}
/// Sets an `href` attribute in preference over an `xlink:href` one.
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 4a811ed6..b7933cfb 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -12,6 +12,7 @@
//! [`NodeData`]: struct.NodeData.html
use markup5ever::QualName;
+use matches::matches;
use std::cell::{Ref, RefMut};
use std::fmt;
@@ -193,17 +194,11 @@ pub trait NodeBorrow {
impl NodeBorrow for Node {
fn is_element(&self) -> bool {
- match *self.borrow() {
- NodeData::Element(_) => true,
- _ => false,
- }
+ matches!(*self.borrow(), NodeData::Element(_))
}
fn is_chars(&self) -> bool {
- match *self.borrow() {
- NodeData::Text(_) => true,
- _ => false,
- }
+ matches!(*self.borrow(), NodeData::Text(_))
}
fn borrow_chars(&self) -> Ref<Chars> {
@@ -231,7 +226,7 @@ impl NodeBorrow for Node {
#[macro_export]
macro_rules! is_element_of_type {
($node:expr, $element_type:ident) => {
- matches::matches!(
+ matches!(
*$node.borrow_element(),
crate::element::Element::$element_type(_)
)
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index d921688a..8436f34d 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -1,6 +1,7 @@
//! The `pattern` element.
use markup5ever::{expanded_name, local_name, namespace_url, ns};
+use matches::matches;
use std::cell::RefCell;
use crate::aspect_ratio::*;
@@ -263,10 +264,7 @@ impl UnresolvedChildren {
}
fn is_resolved(&self) -> bool {
- match *self {
- UnresolvedChildren::Unresolved => false,
- _ => true,
- }
+ !matches!(*self, UnresolvedChildren::Unresolved)
}
fn resolve_from_fallback(&self, fallback: &UnresolvedChildren) -> UnresolvedChildren {
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index b2ad2245..775f9551 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -24,6 +24,7 @@ use cssparser::{
use markup5ever::{
expanded_name, local_name, namespace_url, ns, ExpandedName, LocalName, QualName,
};
+use matches::matches;
use std::collections::HashSet;
use crate::attributes::Attributes;
@@ -106,10 +107,7 @@ impl Default for SpecifiedValues {
impl ComputedValues {
pub fn is_overflow(&self) -> bool {
- match self.overflow() {
- Overflow::Auto | Overflow::Visible => true,
- _ => false,
- }
+ matches!(self.overflow(), Overflow::Auto | Overflow::Visible)
}
pub fn is_visible(&self) -> bool {
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index ee1b8f2a..8c01a1af 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -44,6 +44,7 @@
use std::convert::TryInto;
use cssparser::{Parser, Token};
+use matches::matches;
use crate::dasharray::Dasharray;
use crate::error::*;
@@ -882,10 +883,7 @@ make_property!(
impl WritingMode {
pub fn is_vertical(self) -> bool {
- match self {
- WritingMode::Tb | WritingMode::TbRl => true,
- _ => false,
- }
+ matches!(self, WritingMode::Tb | WritingMode::TbRl)
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]