Skip to content

Conversation

@jgiles
Copy link

@jgiles jgiles commented Aug 9, 2025

This is most useful for generic "wrapper" types that add behavior to a contained value.

These kinds of wrappers can be useful for configuration values:

  • A wrapper for sensitive values with protections against printing or logging.
  • A wrapper integrating with a scheme for dynamic configuration changes.

The desirable behavior for a wrapper containing a value of type T is for the envconfig facilities to apply for decoding the contained value. Achieving this behavior today requires duplicating much of the logic in processField in a custom Decode method on the wrapper, in order to handle all the various types of values that might be contained.

Instead, this commit introduces support for arbitrary Set(value T) methods by first decoding into a new T and then calling the Set method.

This is most useful for generic "wrapper" types that add behavior to
a contained value.

These kinds of wrappers can be useful for configuration values:
- A wrapper for sensitive values with protections against printing or
  logging.
- A wrapper integrating with a scheme for dynamic configuration changes.

The desirable behavior for a wrapper containing a value of type T is for
the envconfig facilities to apply for decoding the contained value.
Achieving this behavior today requires duplicating much of the logic in
`processField` in a custom `Decode` method on the wrapper, in order to
handle all the various types of values that might be contained.

Instead, this commit introduces support for abitrary Set(value T)
methods by first decoding into a new T and then calling the Set method.
@jgiles
Copy link
Author

jgiles commented Sep 2, 2025

Ping @kelishightower @teepark

1 similar comment
@jgiles
Copy link
Author

jgiles commented Oct 3, 2025

Ping @kelishightower @teepark

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.

1 participant