github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/reflectlite/type.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package reflectlite implements lightweight version of reflect, not using 6 // any package except for "runtime", "unsafe", and "internal/abi" 7 package reflectlite 8 9 import ( 10 "github.com/shogo82148/std/internal/abi" 11 ) 12 13 // Type is the representation of a Go type. 14 // 15 // Not all methods apply to all kinds of types. Restrictions, 16 // if any, are noted in the documentation for each method. 17 // Use the Kind method to find out the kind of type before 18 // calling kind-specific methods. Calling a method 19 // inappropriate to the kind of type causes a run-time panic. 20 // 21 // Type values are comparable, such as with the == operator, 22 // so they can be used as map keys. 23 // Two Type values are equal if they represent identical types. 24 type Type interface { 25 Name() string 26 27 PkgPath() string 28 29 Size() uintptr 30 31 Kind() Kind 32 33 Implements(u Type) bool 34 35 AssignableTo(u Type) bool 36 37 Comparable() bool 38 39 String() string 40 41 Elem() Type 42 43 common() *abi.Type 44 uncommon() *uncommonType 45 } 46 47 // A Kind represents the specific kind of type that a Type represents. 48 // The zero Kind is not a valid kind. 49 type Kind = abi.Kind 50 51 const Ptr = abi.Pointer 52 53 const ( 54 // Import-and-export these constants as necessary 55 Interface = abi.Interface 56 Slice = abi.Slice 57 String = abi.String 58 Struct = abi.Struct 59 ) 60 61 // TypeOf returns the reflection Type that represents the dynamic type of i. 62 // If i is a nil interface value, TypeOf returns nil. 63 func TypeOf(i any) Type