diff --git a/Cargo.lock b/Cargo.lock index a48aebe..4af079c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2752,6 +2752,7 @@ dependencies = [ name = "validate_theme_derive" version = "0.1.0" dependencies = [ + "log", "quote", "syn 2.0.99", ] diff --git a/proc_macros/enum_display_style_derive/src/lib.rs b/proc_macros/enum_display_style_derive/src/lib.rs index 9d8f360..3e2c941 100644 --- a/proc_macros/enum_display_style_derive/src/lib.rs +++ b/proc_macros/enum_display_style_derive/src/lib.rs @@ -5,7 +5,7 @@ use darling::FromVariant; use quote::quote; use syn::{Data, DeriveInput, parse_macro_input}; -/// Derive macro for the EnumDisplayStyle trait. +/// Derive macro for generating a `to_display_str` method for an enum. /// /// # Example /// @@ -16,13 +16,12 @@ use syn::{Data, DeriveInput, parse_macro_input}; /// /// #[derive(EnumDisplayStyle)] /// enum Weekend { -/// Saturday, -/// Sunday, +/// Saturday, +/// Sunday, /// } /// /// assert_eq!(Weekend::Saturday.to_display_str(), "Saturday"); /// assert_eq!(Weekend::Sunday.to_display_str(), "Sunday"); -/// /// ``` /// /// Using custom values for the display style: @@ -32,10 +31,10 @@ use syn::{Data, DeriveInput, parse_macro_input}; /// /// #[derive(EnumDisplayStyle)] /// enum MonitorStatus { -/// #[display_style(name = "Monitor Transactions")] -/// Active, -/// #[display_style(name = "Don't Monitor Transactions")] -/// None, +/// #[display_style(name = "Monitor Transactions")] +/// Active, +/// #[display_style(name = "Don't Monitor Transactions")] +/// None, /// } /// /// assert_eq!(MonitorStatus::Active.to_display_str(), "Monitor Transactions"); diff --git a/proc_macros/validate_theme_derive/Cargo.toml b/proc_macros/validate_theme_derive/Cargo.toml index 8c55170..084f7a4 100644 --- a/proc_macros/validate_theme_derive/Cargo.toml +++ b/proc_macros/validate_theme_derive/Cargo.toml @@ -9,3 +9,6 @@ proc-macro = true [dependencies] quote = "1.0.39" syn = "2.0.99" + +[dev-dependencies] +log = "0.4.17" diff --git a/proc_macros/validate_theme_derive/src/lib.rs b/proc_macros/validate_theme_derive/src/lib.rs index d82648b..686beea 100644 --- a/proc_macros/validate_theme_derive/src/lib.rs +++ b/proc_macros/validate_theme_derive/src/lib.rs @@ -2,6 +2,69 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, Data, DeriveInput, Fields}; +/// Derive macro for generating a `validate` method for a Theme struct. +/// The `validate` method ensures that all values with the `validate` attribute are not `None`. +/// Otherwise, an error message it output to both the log file and stdout and the program exits. +/// +/// # Example +/// +/// Valid themes pass through the program transitively without any messages being output. +/// +/// ``` +/// use validate_theme_derive::ValidateTheme; +/// +/// #[derive(ValidateTheme, Default)] +/// struct Theme { +/// pub name: String, +/// #[validate] +/// pub good: Option