docs: Add comprehensive Gonfig derive macro documentation - #17
Conversation
There was a problem hiding this comment.
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.
| /// ``` | ||
| /// | ||
| /// ## `#[Gonfig(allow_config)]` | ||
| /// Automatically loads from `config.{toml,yaml,json}` in current directory. |
There was a problem hiding this comment.
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)'.
| /// 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). |
| 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(); |
There was a problem hiding this comment.
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.
Summary
Changes
Documentation (gonfig_derive/src/lib.rs)
Added 153 lines of comprehensive documentation including:
from_gonfig(),from_gonfig_with_builder(), andgonfig_builder()env_prefix,allow_cli,allow_configenv_name,cli_name,default,skip/skip_gonfigCode Simplification
setup_env_clicode block to eliminate duplication betweenfrom_gonfig_with_builder()andgonfig_builder()methods["config.toml", "config.yaml", "config.json"]allow_envvariable (environment is always enabled)Code Quality
Fixed
clippy::uninlined_format_argswarnings in core library:src/builder.rssrc/cli.rssrc/config.rsBenefits
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
-D warnings