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

Optionals #7

Open
ufukty opened this issue Jun 22, 2024 · 1 comment
Open

Optionals #7

ufukty opened this issue Jun 22, 2024 · 1 comment
Labels
discussions features Feature requests

Comments

@ufukty
Copy link
Owner

ufukty commented Jun 22, 2024

Current behavior

Currently marking targets as optionals is not possible. The resulting struct will contain basic/composed type regardless.

struct Config type {
  A int `yaml:"a"`
}

Proposed behavior

Providing an interface to user to let specify which targets can be optional. Then, implement additional types based on contains the value as a field, and also contains the state of value in another field, named IsSet.

type Optional[T any] struct {
  Value T
  IsSet bool
}

struct Config type {
  A Optional[int] `yaml:"a"`
}

See also

@ufukty ufukty added features Feature requests discussions labels Jun 22, 2024
@ufukty
Copy link
Owner Author

ufukty commented Sep 8, 2024

One method is allowing user to manually assign type, than using types like null.String will provide the functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussions features Feature requests
Projects
None yet
Development

No branches or pull requests

1 participant