Skip to main content

builder

Function builder 

Source
pub fn builder<'a, S>(store: S) -> ConfigMenu<'a, S>
where S: SettingsStore,
Expand description

Creates a configurable settings menu for the provided settings store.

By default, the menu reads from settings(key, value) and orders rows by key. Use the returned ConfigMenu to customize table names, secret keys, validation, ordering, or custom actions before calling ConfigMenu::run.

Examples found in repository?
examples/custom_store.rs (line 51)
48fn main() {
49    let store = AppSettings::new();
50
51    let _ = config_easy::builder(store)
52        .secret_keys(["api_token"])
53        .validator(|key, value| {
54            if key == "log_level" && !["debug", "info", "warn", "error"].contains(&value) {
55                return Err(std::io::Error::new(
56                    std::io::ErrorKind::InvalidInput,
57                    "expected one of debug, info, warn, error",
58                )
59                .into());
60            }
61
62            Ok(())
63        })
64        .action("reset", "reset settings", || {
65            println!("Reset settings here.");
66            Ok(())
67        })
68        .run();
69}