feat: support HashSet and BTreeSet as TOML arrays#77
Open
foxcyber907 wants to merge 1 commit into
Open
Conversation
Treat HashSet<T> and BTreeSet<T> identically to Vec<T> in parse_type so that struct fields using these collection types can derive TomlExample without manual TomlExample impls. Both serialize to TOML arrays via serde, so the existing Vec codegen path applies unchanged. Adds test hashset_btreeset covering required, optional, and BTreeSet forms.
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.
Summary
Extends
parse_typein the derive macro to recognizeHashSet<T>andBTreeSet<T>alongsideVec<T>. All three serialize to TOML arrays via serde, so the existingVeccodegen path applies unchanged.Motivation
Currently a struct field like
tags: HashSet<String>fails to deriveTomlExample(the type is silently ignored byparse_type, which then emits no example for the field). Users have to either rewrite the field asVec<String>or write a manualimpl TomlExample. This patch removes that friction without changing any existing behavior.Changes
derive/src/lib.rs: change theVecarm ofparse_typetoVec | HashSet | BTreeSetand update the doc comment.lib/src/lib.rs: addhashset_btreesettest covering requiredHashSet<String>,BTreeSet<usize>, andOption<HashSet<String>>, with round-trip parse verification.Test plan
cargo test --workspace— all 38 tests pass (37 existing + 1 new)toml::from_str