params: add Defined

This commit is contained in:
Felix Lange 2025-08-06 23:01:51 +02:00
parent 11ac2cc80f
commit ee78ae4172

View file

@ -39,6 +39,15 @@ func (p Parameter[V]) Get(cfg *Config2) V {
return p.info.defaultValue.(V) return p.info.defaultValue.(V)
} }
// Defined reports whether the parameter is set in the config.
func (p Parameter[V]) Defined(cfg *Config2) bool {
if p.info.id == 0 {
panic("zero parameter")
}
_, ok := cfg.param[p.info.id]
return ok
}
// V creates a ParamValue with the given value. You need this to // V creates a ParamValue with the given value. You need this to
// specify parameter values when constructing a Config in code. // specify parameter values when constructing a Config in code.
func (p Parameter[V]) V(v V) ParamValue { func (p Parameter[V]) V(v V) ParamValue {