Derive macros for rcman settings library.
This crate provides #[derive(SettingsSchema)] for automatically generating
settings schema implementations from Rust structs. It translates strongly-typed
native Rust definitions directly into runtime rcman::SettingMetadata, preventing bugs
and ensuring absolute schema correctness via compile-time semantic validation.
Features
- Native Type Binding: Automatically translates
String,PathBuf, integers, floats,bool, andVec<T>into their correspondingrcman::SettingType. - Strict Verification: The macro prevents contradictory constraints at compile time (e.g.
min > maxoroptionsonbool). - Dynamic UI Metadata: Every unknown attribute literal (e.g.,
label = "Server") is automatically injected into the schema as customizable metadata. #[cfg]Forwarding: Safely obeys macro feature flags attached to struct fields.
Usage
use DeriveSettingsSchema as SettingsSchema;
use ;
// Required: sets the root prefix for the UI
Attribute Reference
Container Attributes (#[schema(...)])
Apply these directly to the struct.
| Attribute | Description | Required | Example |
|---|---|---|---|
category |
The root grouping prefix used for all fields. | Yes | #[schema(category = "general")] |
Field Attributes (#[setting(...)])
Apply these to individual struct fields.
| Attribute | Type Mapping | Description | Example |
|---|---|---|---|
rename |
All | Overrides the field name when constructing the schema key (category.rename) |
#[setting(rename = "App-Theme")] |
skip |
All | Silently ignores the field; it will not appear in the settings schema | #[setting(skip)] |
secret |
All | Asserts the field contains sensitive data, diverting it to the OS Keychain backing | #[setting(secret)] |
category |
All | Overrides the container category specifically for this single field |
#[setting(category = "overridden")] |
nested |
Structs | Extracts the schema from an inner struct and flattens it upward | #[setting(nested)] |
min |
Number | Sets a numeric minimum constraint (must be <= max) |
#[setting(min = 1.0)] |
max |
Number | Sets a numeric maximum constraint (must be >= min) |
#[setting(max = 100.0)] |
step |
Number | Defines valid increment stepping | #[setting(step = 5.0)] |
pattern |
Text | Enforces standard Regex validation string | #[setting(pattern = "^[a-z]+$")] |
options |
Text/Num | Enforces strict dropdown alternatives mappings | #[setting(options(("val", "Label")))] |
Dynamic Metadata
Any key = value assignment in #[setting(...)] that isn't functionally reserved above is transparently forwarded into the resulting SettingMetadata map for your UI components to access dynamically.
use DeriveSettingsSchema as SettingsSchema;
use ;
Panics
This macro performs completely safe compile-time error reporting (yielding syn::Error) returning targeted IDE-friendly error underlines instead of panicking. It blocks:
- Setting
min/max/stepon non-numeric types (bool,Vec,String). - Setting
patternon non-Text types (bool,Vec,i32). - Unknown/Unsupported types missing
#[setting(skip)](e.g.DurationorHashMap) so that you never accidentally leak invalid config metadata to the UI.