Trait aquatic_toml_config::TomlConfig
source · pub trait TomlConfig: Default {
// Required method
fn default_to_string() -> String;
}
Expand description
Export structs to toml, converting Rust doc strings to comments.
Supports one level of nesting. Fields containing structs must come after regular fields.
Usage:
use aquatic_toml_config::TomlConfig;
#[derive(TomlConfig)]
struct SubConfig {
/// A
a: usize,
/// B
b: String,
}
impl Default for SubConfig {
fn default() -> Self {
Self {
a: 200,
b: "subconfig hello".into(),
}
}
}
#[derive(TomlConfig)]
struct Config {
/// A
a: usize,
/// B
b: String,
/// C
c: SubConfig,
}
impl Default for Config {
fn default() -> Self {
Self {
a: 100,
b: "hello".into(),
c: Default::default(),
}
}
}
let expected = "# A\na = 100\n# B\nb = \"hello\"\n\n# C\n[c]\n# A\na = 200\n# B\nb = \"subconfig hello\"\n";
assert_eq!(
Config::default_to_string(),
expected,
);
Required Methods§
fn default_to_string() -> String
Object Safety§
This trait is not object safe.