Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make Set directly JSON-unmarshable #87

Merged

Conversation

costela
Copy link
Contributor

@costela costela commented Aug 1, 2024

Currently, Set implements json.Unmarshaler, but it actually panics if you try to use it like this:

type Foo struct {
  Bar *set.Set[string]
}

var f Foo

json.Unmarshal(x, &f)

This PR makes this work for Set, with the minor price of nil checks.
It also makes the zero *Set[T] type directly usable.

TreeSet and HashSet unfortunately cannot be made to support this without further work. The need for external definitions of CompareFunc/HashFunc mean one cannot derive a usable set from the type parameters alone (see the commented-out tests).

Copy link

hashicorp-cla-app bot commented Aug 1, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

LGTM; thanks @costela!

@shoenig shoenig merged commit 50ad671 into hashicorp:main Aug 16, 2024
4 checks passed
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