Skip to content

Commit

Permalink
feat: use generics instead of reflection for AnyPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrs committed Jan 13, 2025
1 parent 1ad4079 commit a347f81
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions convert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package cloudflare

import (
"reflect"
"time"
)

Expand All @@ -42,10 +41,8 @@ import (
// var _ *uint16 = AnyPtr(uint16(16)).(*uint16)
// var _ *uint32 = AnyPtr(uint32(32)).(*uint32)
// var _ *uint64 = AnyPtr(uint64(64)).(*uint64)
func AnyPtr(v interface{}) interface{} {
r := reflect.New(reflect.TypeOf(v))
reflect.ValueOf(r.Interface()).Elem().Set(reflect.ValueOf(v))
return r.Interface()
func AnyPtr[T any](v T) *T {
return &v
}

// BytePtr is a helper routine that allocates a new byte value to store v and
Expand Down

0 comments on commit a347f81

Please sign in to comment.