From 439b641fbf8adedee99aeb4fee7c7d2d5afdfa37 Mon Sep 17 00:00:00 2001 From: Wei Zhang Date: Fri, 29 Jul 2022 01:35:01 +0800 Subject: [PATCH] :recycle: refactor theme read file to de trait --- src/color.rs | 2 +- src/theme.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/color.rs b/src/color.rs index 44f193c..db4f140 100644 --- a/src/color.rs +++ b/src/color.rs @@ -138,7 +138,7 @@ impl Colors { let theme = match t { ThemeOption::NoColor => None, ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default().color), - ThemeOption::Custom(ref file) => Some(Theme::from_path(file).unwrap_or_default().color), + ThemeOption::Custom(ref file) => Some(Theme::from_path::(file).unwrap_or_default()), }; let lscolors = match t { ThemeOption::Default | ThemeOption::Custom(_) => { diff --git a/src/theme.rs b/src/theme.rs index 8223e24..352395a 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,7 +1,7 @@ pub mod color; pub mod icon; -use serde::Deserialize; +use serde::{Deserialize, de::DeserializeOwned}; use std::path::Path; use std::fs; @@ -34,7 +34,7 @@ impl Theme { /// This read theme from file, /// use the file path if it is absolute /// prefix the config_file dir to it if it is not - pub fn from_path(file: &str) -> Option { + pub fn from_path(file: &str) -> Option { let real = if let Some(path) = config_file::Config::expand_home(file) { path } else { @@ -76,7 +76,7 @@ impl Theme { } /// This constructs a Theme struct with a passed [Yaml] str. - fn with_yaml(yaml: &str) -> Result { - serde_yaml::from_str::(yaml) + fn with_yaml(yaml: &str) -> Result { + serde_yaml::from_str::(yaml) } }