Refactor config_trait crate and add doc comment examples

This commit is contained in:
Luke D. Jones
2023-01-08 20:41:17 +13:00
parent 5133d398eb
commit 00839aaa6f
6 changed files with 177 additions and 107 deletions

View File

@@ -28,12 +28,12 @@ impl StdConfig for Config {
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FILE
fn file_name(&self) -> String {
CONFIG_FILE.to_string()
}
}
impl StdConfigLoad3<Config, Config455, Config458> for Config {}
impl StdConfigLoad3<Config455, Config458> for Config {}
#[derive(Deserialize, Serialize, Default)]
#[serde(default)]

View File

@@ -144,12 +144,12 @@ impl StdConfig for AnimeConfig {
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FILE
fn file_name(&self) -> String {
CONFIG_FILE.to_string()
}
}
impl StdConfigLoad3<AnimeConfig, AnimeConfigV341, AnimeConfigV352> for AnimeConfig {}
impl StdConfigLoad3<AnimeConfigV341, AnimeConfigV352> for AnimeConfig {}
impl AnimeConfig {
// fn clamp_config_brightness(mut config: &mut AnimeConfig) {

View File

@@ -194,12 +194,12 @@ impl StdConfig for AuraConfig {
std::path::PathBuf::from(crate::CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FILE
fn file_name(&self) -> String {
CONFIG_FILE.to_string()
}
}
impl StdConfigLoad1<AuraConfig> for AuraConfig {}
impl StdConfigLoad1 for AuraConfig {}
impl AuraConfig {
fn create_default(support_data: &LaptopLedData) -> Self {

View File

@@ -27,12 +27,12 @@ impl StdConfig for ProfileConfig {
PathBuf::from(CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FILE
fn file_name(&self) -> String {
CONFIG_FILE.to_string()
}
}
impl StdConfigLoad1<ProfileConfig> for ProfileConfig {}
impl StdConfigLoad1 for ProfileConfig {}
#[derive(Deserialize, Serialize, Debug, Default)]
pub struct FanCurveConfig {
@@ -76,9 +76,9 @@ impl StdConfig for FanCurveConfig {
PathBuf::from(CONFIG_PATH_BASE)
}
fn file_name() -> &'static str {
CONFIG_FAN_FILE
fn file_name(&self) -> String {
CONFIG_FAN_FILE.to_string()
}
}
impl StdConfigLoad1<ProfileConfig> for FanCurveConfig {}
impl StdConfigLoad1 for FanCurveConfig {}

View File

@@ -6,7 +6,7 @@ use std::time::Duration;
use ::zbus::export::futures_util::lock::Mutex;
use ::zbus::Connection;
use config_traits::{StdConfigLoad1, StdConfigLoad3};
use config_traits::{StdConfig, StdConfigLoad1, StdConfigLoad3};
use daemon::config::Config;
use daemon::ctrl_anime::config::AnimeConfig;
use daemon::ctrl_anime::trait_impls::CtrlAnimeZbus;
@@ -71,7 +71,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
// Start zbus server
let mut connection = Connection::system().await?;
let config = Config::load();
let config = Config::new().load();
let config = Arc::new(Mutex::new(config));
supported.add_to_server(&mut connection).await;
@@ -97,7 +97,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
}
if Profile::is_platform_profile_supported() {
let profile_config = ProfileConfig::load();
let profile_config = ProfileConfig::new().load();
match CtrlPlatformProfile::new(profile_config) {
Ok(ctrl) => {
let zbus = ProfileZbus(Arc::new(Mutex::new(ctrl)));
@@ -112,7 +112,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
warn!("platform_profile support not found");
}
match CtrlAnime::new(AnimeConfig::load()) {
match CtrlAnime::new(AnimeConfig::new().load()) {
Ok(ctrl) => {
let zbus = CtrlAnimeZbus(Arc::new(Mutex::new(ctrl)));
let sig_ctx = CtrlAnimeZbus::signal_context(&connection)?;
@@ -124,7 +124,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
}
let laptop = LaptopLedData::get_data();
let aura_config = AuraConfig::load();
let aura_config = AuraConfig::new().load();
match CtrlKbdLed::new(laptop, aura_config) {
Ok(ctrl) => {
let zbus = CtrlKbdLedZbus(Arc::new(Mutex::new(ctrl)));