[librsvg: 4/19] Use as_deref() instead of `.as_ref().map(String::as_str)` on an Option value




commit 92c847035d7dfd0857912afcfa5a967ff65c577f
Author: Sven Neumann <sven svenfoo org>
Date:   Thu Aug 20 20:12:13 2020 +0200

    Use as_deref() instead of `.as_ref().map(String::as_str)` on an Option value
    
    See https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref

 rsvg_internals/src/allowed_url.rs | 9 ++-------
 rsvg_internals/src/document.rs    | 9 ++++-----
 rsvg_internals/src/element.rs     | 4 ++--
 3 files changed, 8 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/allowed_url.rs b/rsvg_internals/src/allowed_url.rs
index 71f56baea..3a99e00b8 100644
--- a/rsvg_internals/src/allowed_url.rs
+++ b/rsvg_internals/src/allowed_url.rs
@@ -187,7 +187,7 @@ impl Fragment {
     }
 
     pub fn uri(&self) -> Option<&str> {
-        self.0.as_ref().map(|s| s.as_str())
+        self.0.as_deref()
     }
 
     pub fn fragment(&self) -> &str {
@@ -197,12 +197,7 @@ impl Fragment {
 
 impl fmt::Display for Fragment {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(
-            f,
-            "{}#{}",
-            self.0.as_ref().map(String::as_str).unwrap_or(""),
-            self.1
-        )
+        write!(f, "{}#{}", self.uri().unwrap_or(""), self.fragment())
     }
 }
 
diff --git a/rsvg_internals/src/document.rs b/rsvg_internals/src/document.rs
index dac32ac79..eebb5c02e 100644
--- a/rsvg_internals/src/document.rs
+++ b/rsvg_internals/src/document.rs
@@ -206,7 +206,7 @@ fn load_image(
     // Adobe Illustrator generate data: URLs without MIME-type for image
     // data.  We'll catch this and fall back to sniffing by unsetting the
     // content_type.
-    if content_type.as_ref().map(String::as_str) == Some("text/plain;charset=US-ASCII") {
+    if content_type.as_deref() == Some("text/plain;charset=US-ASCII") {
         content_type = None;
     }
 
@@ -227,8 +227,7 @@ fn load_image(
         None
     };
 
-    let surface =
-        SharedImageSurface::from_pixbuf(&pixbuf, bytes, content_type.as_ref().map(String::as_str))?;
+    let surface = SharedImageSurface::from_pixbuf(&pixbuf, bytes, content_type.as_deref())?;
 
     Ok(surface)
 }
@@ -380,8 +379,8 @@ impl DocumentBuilder {
         type_: Option<String>,
         href: &str,
     ) -> Result<(), LoadingError> {
-        if type_.as_ref().map(String::as_str) != Some("text/css")
-            || (alternate.is_some() && alternate.as_ref().map(String::as_str) != Some("no"))
+        if type_.as_deref() != Some("text/css")
+            || (alternate.is_some() && alternate.as_deref() != Some("no"))
         {
             return Err(LoadingError::BadStylesheet);
         }
diff --git a/rsvg_internals/src/element.rs b/rsvg_internals/src/element.rs
index a90914b1c..1f87202a5 100644
--- a/rsvg_internals/src/element.rs
+++ b/rsvg_internals/src/element.rs
@@ -115,11 +115,11 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
     }
 
     fn get_id(&self) -> Option<&str> {
-        self.id.as_ref().map(String::as_str)
+        self.id.as_deref()
     }
 
     fn get_class(&self) -> Option<&str> {
-        self.class.as_ref().map(String::as_str)
+        self.class.as_deref()
     }
 
     fn get_specified_values(&self) -> &SpecifiedValues {


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