Merged
Conversation
Introduces the plugin-based loading abstraction that replaces manual Source wiring. Loaders declare what identifiers they handle via provides() and are discoverable through the registry (coming next). FileLoader handles bare names, file:// URLs, and explicit paths by delegating to the existing discovery module.
Introduces the Formatter trait that separates format parsing from source loading. Each formatter declares what extensions it handles and provides serialize/deserialize methods. Extracts all parsing logic from the monolithic formats.rs into individual formatter modules: json, yaml, toml, ini, xml. The old formats.rs remains for backward compatibility during the transition.
Loaders and formatters now self-register at link time via inventory::submit!. The registry finds the right loader/formatter by calling provides() on each registered plugin. All built-in loaders (FileLoader) and formatters (json, yaml, toml, ini, xml) are auto-registered. External crates like prefer_db can register their own plugins by depending on prefer and submitting to the inventory.
Adds NoLoaderFound, NoFormatterFound, and WatchNotSupported error variants for the registry-based loading path. Adds an Emitter type for "changed" events, matching Python prefer's event system. Config will use this to notify listeners when values are set or updated.
…stry
Config now holds loader_name, formatter_name, and source metadata from
the loading path. Adds set() method with event emission via on_change().
Clone drops the emitter (event handlers are instance-specific).
The top-level load() and watch() functions now route through the
registry: find_loader -> load -> find_formatter -> deserialize. This
means prefer::load("postgres://...") will work when prefer_db registers
its DbLoader.
Source and FileSource are deprecated in favor of Loader + Formatter. EnvSource, MemorySource, LayeredSource, and ConfigBuilder remain functional for layering use cases. Adds comprehensive registry tests covering loader discovery, formatter matching by extension and hint, the full load pipeline through the registry, and Config::set() with event emission.
Cover serialize/deserialize paths for all formatters (JSON, YAML, TOML, INI, XML), Config metadata and event edge cases, error Display variants, and formatter mod utilities. Coverage 73.95% -> 83.68%.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2 +/- ##
==========================================
+ Coverage 91.37% 93.85% +2.47%
==========================================
Files 11 21 +10
Lines 2133 3610 +1477
Branches 2133 3610 +1477
==========================================
+ Hits 1949 3388 +1439
- Misses 147 174 +27
- Partials 37 48 +11
🚀 New features to boost your workflow:
|
Replace unnecessary if-let nesting with guards, extract duplicated escape helpers, remove unnecessary closures (or_else -> or, ok_or_else -> ok_or), and restructure XML text parsing into a match.
Use slice::contains instead of iter().any() in extension/hint matching, and use EventHandler type alias in Config::on_change signature.
Use 3.15 instead of 3.14 to avoid approx_constant lint, and add allow(deprecated) to coverage_tests.rs which intentionally tests the deprecated Source/FileSource API.
This reverts commit cc8692f.
Move tests using deprecated Source/FileSource API from coverage_tests.rs into source.rs where allow(deprecated) is already set. Use 3.15 instead of 3.14 in test floats to avoid approx_constant lint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.