变更 interface{} => any

This commit is contained in:
2024-06-08 20:06:35 +08:00
parent 3faebb9145
commit 588df729e0
13 changed files with 59 additions and 59 deletions

View File

@ -38,7 +38,7 @@ var errNilPtr = errors.New("destination pointer is nil") // embedded in descript
// convertAssign copies to dest the value in src, converting it if possible.
// An error is returned if the copy would result in loss of information.
// dest should be a pointer type.
func ConvertAssign(dest, src interface{}) error {
func ConvertAssign(dest, src any) error {
// Common cases, without reflect.
switch s := src.(type) {
case string:
@ -70,7 +70,7 @@ func ConvertAssign(dest, src interface{}) error {
}
*d = string(s)
return nil
case *interface{}:
case *any:
if d == nil {
return errNilPtr
}
@ -112,7 +112,7 @@ func ConvertAssign(dest, src interface{}) error {
}
case nil:
switch d := dest.(type) {
case *interface{}:
case *any:
if d == nil {
return errNilPtr
}
@ -164,7 +164,7 @@ func ConvertAssign(dest, src interface{}) error {
*d = bv.(bool)
}
return err
case *interface{}:
case *any:
*d = src
return nil
}
@ -271,11 +271,11 @@ func cloneBytes(b []byte) []byte {
return c
}
func ToString(src interface{}) string {
func ToString(src any) string {
return asString(src)
}
func asString(src interface{}) string {
func asString(src any) string {
switch v := src.(type) {
case string:
return v
@ -327,14 +327,14 @@ func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) {
// []byte
// string
// time.Time
type Value interface{}
type Value any
type boolType struct{}
var Bool boolType
func (boolType) String() string { return "Bool" }
func (boolType) ConvertValue(src interface{}) (Value, error) {
func (boolType) ConvertValue(src any) (Value, error) {
switch s := src.(type) {
case bool:
return s, nil
@ -390,5 +390,5 @@ type Scanner interface {
// Reference types such as []byte are only valid until the next call to Scan
// and should not be retained. Their underlying memory is owned by the driver.
// If retention is necessary, copy their values before the next call to Scan.
Scan(src interface{}) error
Scan(src any) error
}