[librsvg/rustify-rsvg-convert] rsvg-convert: apply some cleanups suggested by imperio
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert] rsvg-convert: apply some cleanups suggested by imperio
- Date: Sat, 9 Jan 2021 15:12:04 +0000 (UTC)
commit bdad3f2835334b9b3d564e5520002e01c631da0a
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jan 9 16:05:41 2021 +0100
rsvg-convert: apply some cleanups suggested by imperio
src/bin/rsvg-convert/main.rs | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
---
diff --git a/src/bin/rsvg-convert/main.rs b/src/bin/rsvg-convert/main.rs
index 381b32d0..84d0a5f8 100644
--- a/src/bin/rsvg-convert/main.rs
+++ b/src/bin/rsvg-convert/main.rs
@@ -205,7 +205,7 @@ impl Surface {
pub fn show_page(&self, cr: &cairo::Context) -> Result<(), RenderingError> {
match self {
- Self::Png(_, _) => (),
+ Self::Png(_, _) => {}
_ => cr.show_page(),
}
Ok(())
@@ -565,20 +565,16 @@ impl<T> NotFound for Result<T, clap::Error> {
}
}
-fn parse_color_string(str: String) -> Result<Color, clap::Error> {
- parse_color_str(&str)
-}
-
-fn parse_color_str(str: &str) -> Result<Color, clap::Error> {
- match str {
+fn parse_color_string<T: AsRef<str> + std::fmt::Display>(s: T) -> Result<Color, clap::Error> {
+ match s.as_ref() {
"none" | "None" => Err(clap::Error::with_description(
- str,
+ s.as_ref(),
clap::ErrorKind::ArgumentNotFound,
)),
- _ => <Color as Parse>::parse_str(str).map_err(|_| {
+ _ => <Color as Parse>::parse_str(s.as_ref()).map_err(|_| {
let desc = format!(
"Invalid value: The argument '{}' can not be parsed as a CSS color value",
- str
+ s
);
clap::Error::with_description(&desc, clap::ErrorKind::InvalidValue)
}),
@@ -737,13 +733,13 @@ mod tests {
#[test]
fn valid_color_is_ok() {
- assert!(parse_color_str("Red").is_ok());
+ assert!(parse_color_string("Red").is_ok());
}
#[test]
fn none_is_handled_as_not_found() {
assert_eq!(
- parse_color_str("None").map_err(|e| e.kind),
+ parse_color_string("None").map_err(|e| e.kind),
Err(clap::ErrorKind::ArgumentNotFound)
);
}
@@ -751,7 +747,7 @@ mod tests {
#[test]
fn invalid_is_handled_as_invalid_value() {
assert_eq!(
- parse_color_str("foo").map_err(|e| e.kind),
+ parse_color_string("foo").map_err(|e| e.kind),
Err(clap::ErrorKind::InvalidValue)
);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]