#![feature(default_field_values)]
use v_utils_macros::{LiveSettings, MyConfigPrimitives, Settings};
#[derive(Clone, Debug, Default, LiveSettings, MyConfigPrimitives, Settings)]
#[allow(unused)]
struct AppConfig {
pub port: u16 = 50736,
pub debug: bool = true,
pub workers: usize = 8,
pub maybe_threads: Option<u32> = None,
}
#[test]
fn defaults_take_effect() {
let c = AppConfig::default();
assert_eq!(c.port, 50736);
assert!(c.debug);
assert_eq!(c.workers, 8);
assert!(c.maybe_threads.is_none());
}
#[test]
fn deserialize_uses_field_defaults() {
let c: AppConfig = toml::from_str("").expect("empty config should deserialize via field defaults");
assert_eq!(c.port, 50736);
assert!(c.debug);
assert_eq!(c.workers, 8);
assert!(c.maybe_threads.is_none());
let c: AppConfig = toml::from_str("port = 9000\n").expect("partial config should deserialize");
assert_eq!(c.port, 9000);
assert!(c.debug);
assert_eq!(c.workers, 8);
}
#[test]
fn try_build_signature_compiles() {
let _f: fn(SettingsFlags) -> Result<AppConfig, v_utils::__internal::SettingsError> = AppConfig::try_build;
}