v_utils_macros 2.11.49

Macros for my utils crate
Documentation
#![allow(dead_code, unused_imports)]

use std::time::Duration;

use clap::Parser;
use serde::Serialize;
use v_utils_macros::{LiveSettings, Settings};

/// Example CLI struct using SettingsFlags
#[allow(dead_code)]
#[derive(Debug, Parser)]
struct Cli {
	#[clap(flatten)]
	settings_flags: SettingsFlags,
}
#[test]
fn test() {
	// Test that LiveSettings struct was generated
	let flags = SettingsFlags {
		config: None,
		yes: false,
		host: Some("localhost".to_string()),
		port: Some("8080".to_string()),
		debug: Some(true),
	};

	// Test that LiveSettings::new exists and has correct signature
	let _new_exists: fn(SettingsFlags, Duration) -> v_utils::__internal::eyre::Result<LiveSettings> = LiveSettings::new;

	// Test that LiveSettings is Clone
	fn assert_clone<T: Clone>() {}
	assert_clone::<LiveSettings>();

	// Test that LiveSettings is Debug
	fn assert_debug<T: std::fmt::Debug>() {}
	assert_debug::<LiveSettings>();

	// Test that config() method exists and returns Result<AppConfig, SettingsError>
	// We can't actually call it without a valid config file, but we can verify the signature
	fn check_config_method(ls: &LiveSettings) -> Result<AppConfig, v_utils::__internal::SettingsError> {
		ls.config()
	}

	// Suppress unused warnings
	let _ = flags;
	let _ = check_config_method;
}
/// Settings struct with Default and Serialize for config auto-extension support.
/// When a config field is missing, the macro can offer to extend the config file
/// with default values from Default::default().
#[derive(Clone, Debug, Default, LiveSettings, v_utils_macros::MyConfigPrimitives, Settings)]
struct AppConfig {
	#[serde(default)]
	host: String,
	#[serde(default)]
	port: u16,
	#[serde(default)]
	debug: bool,
}