mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add extra doc comments to config-trait
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -802,10 +802,8 @@ dependencies = [
|
|||||||
"rog_dbus",
|
"rog_dbus",
|
||||||
"rog_platform",
|
"rog_platform",
|
||||||
"rog_profiles",
|
"rog_profiles",
|
||||||
"ron",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
|
||||||
"sysfs-class",
|
"sysfs-class",
|
||||||
"systemd-zbus",
|
"systemd-zbus",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -816,6 +814,7 @@ dependencies = [
|
|||||||
name = "daemon-user"
|
name = "daemon-user"
|
||||||
version = "4.5.8"
|
version = "4.5.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"config-traits",
|
||||||
"dirs",
|
"dirs",
|
||||||
"rog_anime",
|
"rog_anime",
|
||||||
"rog_aura",
|
"rog_aura",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::io::{Read, Write};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
|
pub use ron;
|
||||||
use ron::ser::PrettyConfig;
|
use ron::ser::PrettyConfig;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -13,12 +14,16 @@ pub trait StdConfig
|
|||||||
where
|
where
|
||||||
Self: Serialize + DeserializeOwned,
|
Self: Serialize + DeserializeOwned,
|
||||||
{
|
{
|
||||||
|
/// Taking over the standard `new()` to ensure things can be generic
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
|
|
||||||
|
/// Return the config files names, such as `wibble.cfg`
|
||||||
fn file_name() -> &'static str;
|
fn file_name() -> &'static str;
|
||||||
|
|
||||||
|
/// Return the full path to the directory the config file resides in
|
||||||
fn config_dir() -> PathBuf;
|
fn config_dir() -> PathBuf;
|
||||||
|
|
||||||
|
/// Return the full path to the config file
|
||||||
fn file_path() -> PathBuf {
|
fn file_path() -> PathBuf {
|
||||||
let mut config = Self::config_dir();
|
let mut config = Self::config_dir();
|
||||||
if !config.exists() {
|
if !config.exists() {
|
||||||
@@ -29,6 +34,9 @@ where
|
|||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Directly open the config file for read and write. If the config file
|
||||||
|
/// does not exist it is created, including the directories the file
|
||||||
|
/// resides in.
|
||||||
fn file_open() -> File {
|
fn file_open() -> File {
|
||||||
OpenOptions::new()
|
OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
@@ -38,6 +46,7 @@ where
|
|||||||
.unwrap_or_else(|e| panic!("Could not open {:?} {e}", Self::file_path()))
|
.unwrap_or_else(|e| panic!("Could not open {:?} {e}", Self::file_path()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Open and parse the config file to self from ron format
|
||||||
fn read(&mut self) {
|
fn read(&mut self) {
|
||||||
let mut file = match OpenOptions::new().read(true).open(Self::file_path()) {
|
let mut file = match OpenOptions::new().read(true).open(Self::file_path()) {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
@@ -60,6 +69,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write the config file data to pretty ron format
|
||||||
fn write(&self) {
|
fn write(&self) {
|
||||||
let mut file = match File::create(Self::file_path()) {
|
let mut file = match File::create(Self::file_path()) {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
@@ -100,6 +110,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Base trait for loading/parsing. This can be used to help update configs to
|
||||||
|
/// new versions ```ignore
|
||||||
|
/// impl StdConfigLoad1<FanCurveConfigV1> for FanCurveConfig {}
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// If all of the generics fails to parse, then the old config is renamed and a
|
||||||
|
/// new one created
|
||||||
pub trait StdConfigLoad1<T>
|
pub trait StdConfigLoad1<T>
|
||||||
where
|
where
|
||||||
T: StdConfig + DeserializeOwned + Serialize,
|
T: StdConfig + DeserializeOwned + Serialize,
|
||||||
@@ -127,6 +144,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Base trait for loading/parsing. This is intended to be used to help update
|
||||||
|
/// configs to new versions ```ignore
|
||||||
|
/// impl StdConfigLoad2<FanCurveConfigV1, ProfileConfigV2> for FanCurveConfig {}
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// If all of the generics fails to parse, then the old config is renamed and a
|
||||||
|
/// new one created
|
||||||
pub trait StdConfigLoad2<T1, T2>
|
pub trait StdConfigLoad2<T1, T2>
|
||||||
where
|
where
|
||||||
T1: StdConfig + DeserializeOwned + Serialize,
|
T1: StdConfig + DeserializeOwned + Serialize,
|
||||||
@@ -157,6 +181,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Base trait for loading/parsing. This is intended to be used to help update
|
||||||
|
/// configs to new versions ```ignore
|
||||||
|
/// impl StdConfigLoad3<FanCurveConfigV1, ProfileConfigV2, ProfileConfigV3> for FanCurveConfig {}
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// If all of the generics fails to parse, then the old config is renamed and a
|
||||||
|
/// new one created
|
||||||
pub trait StdConfigLoad3<T1, T2, T3>
|
pub trait StdConfigLoad3<T1, T2, T3>
|
||||||
where
|
where
|
||||||
T1: StdConfig + DeserializeOwned + Serialize,
|
T1: StdConfig + DeserializeOwned + Serialize,
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ rog_anime = { path = "../rog-anime" }
|
|||||||
rog_aura = { path = "../rog-aura" }
|
rog_aura = { path = "../rog-aura" }
|
||||||
rog_dbus = { path = "../rog-dbus" }
|
rog_dbus = { path = "../rog-dbus" }
|
||||||
rog_platform = { path = "../rog-platform" }
|
rog_platform = { path = "../rog-platform" }
|
||||||
|
config-traits = { path = "../config-traits" }
|
||||||
|
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ logind-zbus.workspace = true
|
|||||||
# serialisation
|
# serialisation
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
serde_json.workspace = true
|
|
||||||
ron.workspace = true
|
|
||||||
|
|
||||||
# Device control
|
# Device control
|
||||||
sysfs-class.workspace = true # used for backlight control and baord ID
|
sysfs-class.workspace = true # used for backlight control and baord ID
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use config_traits::ron;
|
||||||
use rog_anime::error::AnimeError;
|
use rog_anime::error::AnimeError;
|
||||||
use rog_platform::error::PlatformError;
|
use rog_platform::error::PlatformError;
|
||||||
use rog_profiles::error::ProfileError;
|
use rog_profiles::error::ProfileError;
|
||||||
|
|||||||
Reference in New Issue
Block a user