possible to allow binding of empty structs?
Closed this issue · 3 comments
I have a library https://github.com/jmhodges/clock, that provides an interface Clock
that is satisfied by an empty struct which is returned by New
.
I've been working in a codebase that uses inject. We tried adding clock.Clock
at an injection point, and only ran into trouble when going to a production-like deploy because inject rejects structs without a pointer.
Is there anyway that restriction could be loosened for empty structs? There's no danger in state getting lost by copy.
Perhaps, there was another reason for that restriction, though. Would love to hear it!
Also, totally aware that you could name the injection and solve the problem that way. But the API only exposes interfaces and people would likely forget that, under the hood, it was really a struct they needed to copy.
The reason we added the restriction was because it was too easy to create multiple instances by simply forgetting the *
in a struct field. There is a "bypass" though, which is to explicitly add the inline
tag like inject:"inline"
. Would that be sufficient for your use case?
I think it's a reasonable thing to special case empty structs here too.
Will consider this "as-designed" for now.