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 ddbab87
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ 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:
//
// var destinationVar *string
// var sourceVar string = "foo"
// pointerize(reflect.TypeOf(destinationVar), reflect.TypeOf(sourceVar), reflect.ValueOf(sourceVar))
//
// This will return a `<*string Value>` that contains `"foo"`
// It handles also type aliases / custom types trying convert when possible.
func pointerize(t, base reflect.Type, v reflect.Value) reflect.Value {
if t == base {
return v
Expand Down

0 comments on commit ddbab87

Please sign in to comment.