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 73a6426
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ 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>`.
// It is supposed to handle conversion to a 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 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 73a6426

Please sign in to comment.