From b7471847889ee2f0faab7e9f9d12df70d351edd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Sun, 8 Sep 2024 17:10:46 +0200 Subject: [PATCH] Accept `impl Into` to avoid cloning strings --- src/theme.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/theme.rs b/src/theme.rs index dcc6ee42..9fbef238 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -84,9 +84,10 @@ impl Default for ThemePreference { impl ThemePreference { /// Creates a theme preference from a string. - pub fn new(s: &str) -> Self { + pub fn new(s: impl Into) -> Self { use ThemePreference::*; - match s { + let s = s.into(); + match s.as_str() { "auto" => Auto(Default::default()), "auto:always" => Auto(DetectColorScheme::Always), "auto:system" => Auto(DetectColorScheme::System), @@ -134,11 +135,12 @@ pub enum ThemeName { impl ThemeName { /// Creates a theme name from a string. - pub fn new(s: &str) -> Self { + pub fn new(s: impl Into) -> Self { + let s = s.into(); if s == "default" { ThemeName::Default } else { - ThemeName::Named(s.to_owned()) + ThemeName::Named(s) } } }