~marcopolo/di

50c247a210a4dd3014d20c9489836e2b0a2bbabe — Marco Munizaga 9 months ago 9a4fa04
allow checking if a Provide is Nil
1 files changed, 2 insertions(+), 0 deletions(-)

M di.go
M di.go => di.go +2 -0
@@ 38,6 38,7 @@ import (
type Provide[Out any] struct {
	fOrV any
	set  bool
	Nil  bool
}

// Optional is the canonical way of specifying a field is optional. The library


@@ 99,6 100,7 @@ func NewProvide[Out any](ctorOrVal any) (Provide[Out], error) {

	if ctorOrVal == nil {
		if canBeNil(outType) {
			out.Nil = true
			return out, nil
		}
		return zero, fmt.Errorf("Provide[%v]: nil not valid for non-nilable type", outType)