You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mir/internal/ref/ref.go

18 lines
208 B
Go

package ref
func New[T any](v *T) Ref[T] {
if v == nil {
var zero T
return Ref[T]{ptr: &zero}
}
return Ref[T]{ptr: v}
}
type Ref[T any] struct {
ptr *T
}
func (r Ref[T]) Val() T {
return *r.ptr
}