Accept impl Into<String> to avoid cloning strings

This commit is contained in:
Tau Gärtli 2024-09-08 17:10:46 +02:00
parent 02ae6ef348
commit b747184788
No known key found for this signature in database

View File

@ -84,9 +84,10 @@ impl Default for ThemePreference {
impl ThemePreference { impl ThemePreference {
/// Creates a theme preference from a string. /// Creates a theme preference from a string.
pub fn new(s: &str) -> Self { pub fn new(s: impl Into<String>) -> Self {
use ThemePreference::*; use ThemePreference::*;
match s { let s = s.into();
match s.as_str() {
"auto" => Auto(Default::default()), "auto" => Auto(Default::default()),
"auto:always" => Auto(DetectColorScheme::Always), "auto:always" => Auto(DetectColorScheme::Always),
"auto:system" => Auto(DetectColorScheme::System), "auto:system" => Auto(DetectColorScheme::System),
@ -134,11 +135,12 @@ pub enum ThemeName {
impl ThemeName { impl ThemeName {
/// Creates a theme name from a string. /// Creates a theme name from a string.
pub fn new(s: &str) -> Self { pub fn new(s: impl Into<String>) -> Self {
let s = s.into();
if s == "default" { if s == "default" {
ThemeName::Default ThemeName::Default
} else { } else {
ThemeName::Named(s.to_owned()) ThemeName::Named(s)
} }
} }
} }