Skip to content

docs: Add comprehensive Gonfig derive macro documentation - #17

Closed
0xvasanth wants to merge 1 commit into
mainfrom
refactor/simplify-derive-macro-implementation
Closed

docs: Add comprehensive Gonfig derive macro documentation#17
0xvasanth wants to merge 1 commit into
mainfrom
refactor/simplify-derive-macro-implementation

Conversation

@0xvasanth

Copy link
Copy Markdown
Owner

Summary

  • Add comprehensive rustdoc documentation for the Gonfig derive macro
  • Simplify derive macro code generation
  • Fix clippy warnings in core library files

Changes

Documentation (gonfig_derive/src/lib.rs)

Added 153 lines of comprehensive documentation including:

  • Generated Methods: Overview of from_gonfig(), from_gonfig_with_builder(), and gonfig_builder()
  • Container Attributes: Detailed docs for env_prefix, allow_cli, allow_config
  • Field Attributes: Complete coverage of env_name, cli_name, default, skip/skip_gonfig
  • Configuration Priority: Clear explanation of how sources are merged
  • Complete Example: Real-world usage demonstrating all features

Code Simplification

  • Extract shared logic: Created reusable setup_env_cli code block to eliminate duplication between from_gonfig_with_builder() and gonfig_builder() methods
  • Simplify config file loading: Replaced verbose if-else chain with clean loop over ["config.toml", "config.yaml", "config.json"]
  • Clean up variable usage: Removed unused allow_env variable (environment is always enabled)
  • Streamline environment key generation: Simplified logic with cleaner pattern matching
  • Remove redundant comments: Cleaned up unnecessary inline comments

Code Quality

Fixed clippy::uninlined_format_args warnings in core library:

  • src/builder.rs
  • src/cli.rs
  • src/config.rs

Benefits

  1. Improved Developer Experience: Comprehensive documentation helps users understand all available options
  2. Reduced Code Duplication: Shared environment/CLI setup logic now in one place (~40 lines eliminated)
  3. Better Maintainability: Future changes only need to be made once
  4. Cleaner Code Flow: Simplified config file loading is easier to understand
  5. Modern Rust Style: All format strings follow inline variable conventions

Note on CI

This PR has clippy warnings in example files. These examples need the fixes from PR #15 to be merged first. The core library changes pass all checks.

Test Plan

  • Documentation builds successfully
  • Core library clippy passes with -D warnings
  • All tests pass
  • No functional changes to derive macro behavior
  • Code simplification preserves exact same functionality

Copilot AI review requested due to automatic review settings October 19, 2025 12:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Add comprehensive rustdoc for the Gonfig derive macro, simplify derive code generation by extracting shared setup logic, and fix clippy inline format warnings in core files.

  • Add detailed rustdoc for container/field attributes, method behavior, and examples
  • Refactor derive macro generation: extract shared environment/CLI setup and simplify config-file discovery
  • Update formatting to satisfy clippy::uninlined_format_args in core modules

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/config.rs Switch to inline formatting in error messages to satisfy clippy and modern Rust style.
src/cli.rs Use inline formatting for serialization error message.
src/builder.rs Use inline formatting for deserialization error message.
gonfig_derive/src/lib.rs Add comprehensive rustdoc and refactor macro generation (shared env/CLI setup, simpler config-file loop).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread gonfig_derive/src/lib.rs
/// ```
///
/// ## `#[Gonfig(allow_config)]`
/// Automatically loads from `config.{toml,yaml,json}` in current directory.

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation for allow_config should clarify the selection semantics and order. The implementation loads only the first existing file in this order: config.toml, then config.yaml, then config.json. Please update the docs to state 'the first existing file among [config.toml, config.yaml, config.json] is loaded (in that order)'.

Suggested change
/// Automatically loads from `config.{toml,yaml,json}` in current directory.
/// Loads the first existing file among [`config.toml`, `config.yaml`, `config.json`] in the current directory (in that order).

Copilot uses AI. Check for mistakes.
Comment thread gonfig_derive/src/lib.rs
Comment on lines 231 to 233
for f in fields.iter().filter(|f| !f.skip_gonfig && !f.skip) {
let field_name = f.ident.as_ref().unwrap();
let field_str = field_name.to_string();

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unwrap() in proc-macros to provide helpful compile-time diagnostics for unsupported forms (e.g., tuple/unit structs). Instead, return a syn::Error with a clear message, e.g., return syn::Error::new_spanned(&f, \"Gonfig requires named fields\").to_compile_error().into(); or collect these errors and abort! accordingly.

Copilot uses AI. Check for mistakes.
@0xvasanth 0xvasanth closed this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants