[librsvg: 4/5] Inline ColorSpec::from() into its only caller



commit df0c689002854386bcf878a84d38863de5e4b334
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jan 14 11:07:39 2020 -0600

    Inline ColorSpec::from() into its only caller

 librsvg/color_utils.rs    | 31 +++++++++++++------------------
 rsvg_internals/src/lib.rs |  2 +-
 2 files changed, 14 insertions(+), 19 deletions(-)
---
diff --git a/librsvg/color_utils.rs b/librsvg/color_utils.rs
index be8d12c9..6b2132ba 100644
--- a/librsvg/color_utils.rs
+++ b/librsvg/color_utils.rs
@@ -2,7 +2,7 @@ use libc;
 
 use std::ffi::CStr;
 
-use rsvg_internals::{Color, Parse, ParseError};
+use rsvg_internals::{Color, Parse};
 
 // There are two quirks here:
 //
@@ -37,27 +37,22 @@ fn rgba_to_argb(r: u8, g: u8, b: u8, a: u8) -> u32 {
     u32::from(a) << 24 | u32::from(r) << 16 | u32::from(g) << 8 | u32::from(b)
 }
 
-impl<'i> From<Result<Color, ParseError<'i>>> for ColorSpec {
-    fn from(result: Result<Color, ParseError<'i>>) -> ColorSpec {
-        match result {
-            Ok(Color::RGBA(rgba)) => ColorSpec {
-                kind: ColorKind::ARGB,
-                argb: rgba_to_argb(rgba.red, rgba.green, rgba.blue, rgba.alpha),
-            },
-
-            _ => ColorSpec {
-                kind: ColorKind::ParseError,
-                argb: 0,
-            },
-        }
-    }
-}
-
 #[no_mangle]
 pub unsafe extern "C" fn rsvg_css_parse_color(string: *const libc::c_char) -> ColorSpec {
     let s = CStr::from_ptr(string).to_string_lossy();
+    let r = <Color as Parse>::parse_str(&s);
+
+    match r {
+        Ok(Color::RGBA(rgba)) => ColorSpec {
+            kind: ColorKind::ARGB,
+            argb: rgba_to_argb(rgba.red, rgba.green, rgba.blue, rgba.alpha),
+        },
 
-    ColorSpec::from(<Color as Parse>::parse_str(&s))
+        _ => ColorSpec {
+            kind: ColorKind::ParseError,
+            argb: 0,
+        },
+    }
 }
 
 #[cfg(test)]
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index d8075c3f..7f589e5c 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -44,7 +44,7 @@ pub use crate::color::Color;
 
 pub use crate::dpi::{rsvg_rust_set_default_dpi_x_y, Dpi};
 
-pub use crate::error::{DefsLookupErrorKind, HrefError, LoadingError, ParseError, RenderingError};
+pub use crate::error::{DefsLookupErrorKind, HrefError, LoadingError, RenderingError};
 
 pub use crate::handle::{
     Handle, LoadOptions, RsvgDimensionData, RsvgPositionData, RsvgSizeFunc, SizeCallback,


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