diff --git a/util.go b/util.go index c3bff93..b8ee725 100644 --- a/util.go +++ b/util.go @@ -128,6 +128,17 @@ func tryTConfig(value reflect.Value) (reflect.Value, bool) { return v.Elem(), true } +// pointerize tries to convert the `reflect.Value` (`v`) of `reflect.Type` (`base`), +// to the destination `reflect.Type` (`t`). For example: `` to `<*string Value>`. +// Mainly it supposes to handle conversion to pointer, of the same type, (as many times as needed). +// E.g. `string` to `*string`, or even `string` to `**string`. +// It also handles the conversion between type aliases / custom types whenever this is possible. +// +// var sourceVar string = "foo" +// var destinationVar *string +// val := pointerize(reflect.TypeOf(destinationVar), reflect.TypeOf(sourceVar), reflect.ValueOf(sourceVar)) +// +// This will return a new `<*string Value>` that contains `"foo"`. func pointerize(t, base reflect.Type, v reflect.Value) reflect.Value { if t == base { return v