mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
Include documentation in printed config files (#41)
* Start work on printing toml config with comments * WIP: toml_config: extract default values for fields * WIP: toml_config: handle single-level nested structs * WIP: toml_config: improve comment handling, std type trait impls * WIP: toml_config: add Private trait, improve comment handling, clean up * toml_config: fix default value bug; improve tests * Use toml_config in all applicable crates; add toml_config enum support * toml_config: improve comments * toml_config_derive: support enum comments * Improve config comments for udp, cli_helpers, common * Improve config comments * Add tests for Config struct TomlConfig implementations * Improve Config comments * Improve Config comments * ws, http: add config comments for tls cert and private key lines * small fixes to toml_config and toml_config_derive * Run cargo fmt * Fix typo in several config comments * Update README * Update README
This commit is contained in:
parent
d694785244
commit
a208775104
28 changed files with 581 additions and 92 deletions
|
|
@ -4,8 +4,10 @@ use std::io::Read;
|
|||
use anyhow::Context;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
|
||||
use toml_config::TomlConfig;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
/// Log level. Available values are off, error, warn, info, debug and trace.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, TomlConfig, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum LogLevel {
|
||||
Off,
|
||||
|
|
@ -22,7 +24,7 @@ impl Default for LogLevel {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait Config: Default + Serialize + DeserializeOwned {
|
||||
pub trait Config: Default + TomlConfig + DeserializeOwned {
|
||||
fn get_log_level(&self) -> Option<LogLevel> {
|
||||
None
|
||||
}
|
||||
|
|
@ -169,9 +171,9 @@ where
|
|||
|
||||
fn default_config_as_toml<T>() -> String
|
||||
where
|
||||
T: Default + Serialize,
|
||||
T: Default + TomlConfig,
|
||||
{
|
||||
toml::to_string_pretty(&T::default()).expect("Could not serialize default config to toml")
|
||||
<T as TomlConfig>::default_to_string()
|
||||
}
|
||||
|
||||
fn start_logger(log_level: LogLevel) -> ::anyhow::Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue