- go version bump
- go fix
This commit is contained in:
12
ptr/ptr.go
12
ptr/ptr.go
@@ -7,8 +7,9 @@ package ptr
|
||||
|
||||
import "strings"
|
||||
|
||||
//go:fix inline
|
||||
func Ref[T string | bool | Num](v T) *T {
|
||||
return &v
|
||||
return new(v)
|
||||
}
|
||||
|
||||
func Deref[T any](v *T) T {
|
||||
@@ -19,16 +20,18 @@ func Deref[T any](v *T) T {
|
||||
return *v
|
||||
}
|
||||
|
||||
//go:fix inline
|
||||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
return new(v)
|
||||
}
|
||||
|
||||
func GetBool(v *bool) bool {
|
||||
return Deref(v)
|
||||
}
|
||||
|
||||
//go:fix inline
|
||||
func Str(v string) *string {
|
||||
return &v
|
||||
return new(v)
|
||||
}
|
||||
|
||||
func GetStr(v *string) string {
|
||||
@@ -48,8 +51,9 @@ type Num interface {
|
||||
uint8 | int8 | uint16 | int16 | uint32 | int32 | uint64 | int64 | uint | int | float32 | float64
|
||||
}
|
||||
|
||||
//go:fix inline
|
||||
func Number[T Num](v T) *T {
|
||||
return &v
|
||||
return new(v)
|
||||
}
|
||||
|
||||
func GetNumber[T Num](v *T) T {
|
||||
|
||||
@@ -4,31 +4,31 @@ import "testing"
|
||||
|
||||
func TestRefDeref(t *testing.T) {
|
||||
a := 10
|
||||
if Deref(Ref(a)) != a {
|
||||
if Deref(new(a)) != a {
|
||||
t.Log("a) had a issue")
|
||||
return
|
||||
}
|
||||
|
||||
b := 10.1
|
||||
if Deref(Ref(b)) != b {
|
||||
if Deref(new(b)) != b {
|
||||
t.Log("b) had a issue")
|
||||
return
|
||||
}
|
||||
|
||||
c := true
|
||||
if Deref(Ref(c)) != c {
|
||||
if Deref(new(c)) != c {
|
||||
t.Log("c) had a issue")
|
||||
return
|
||||
}
|
||||
|
||||
d := "hello there"
|
||||
if Deref(Ref(d)) != d {
|
||||
if Deref(new(d)) != d {
|
||||
t.Log("d) had a issue")
|
||||
return
|
||||
}
|
||||
|
||||
var e string
|
||||
if Deref(Ref(e)) != e {
|
||||
if Deref(new(e)) != e {
|
||||
t.Log("e) had a issue")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user