Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
moukoublen committed Apr 23, 2024
1 parent 447e2b2 commit 12309a1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<string Value>` 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
Expand Down

0 comments on commit 12309a1

Please sign in to comment.