Skip to content

Commit

Permalink
Add utility method to clone a pointer value
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 2, 2024
1 parent 6126777 commit 5776177
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ptr/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

package ptr

func Clone[T any](val *T) *T {
if val == nil {
return nil
}
valCopy := *val
return &valCopy
}

func Ptr[T any](val T) *T {
return &val
}
Expand Down

0 comments on commit 5776177

Please sign in to comment.