contract ptr(t T) {
*t
}
type Ptr struct {
v reflect.Value
}
func PointerOf(type P ptr) (v P) Ptr {
return Ptr{v: reflect.ValueOf(v)}
}
func (p Ptr) Elem() reflect.Value {
return p.v.Elem()
}
contract Stringer(t T) {
// It includes fields
t.String()
}
contract Stringer(t T) {
// Only method
var _ interface{
String() string
} = t
}
contract Field(t T) {
// It includes method
t.Foo
}
A method cannot assign into variable.
contract Field(t T) {
t.Foo = t.Foo
}
Type assertion allows only interface types.
contract Interface (_ T) {
T.(struct{})
}
len
accepts pointers but only array's one.
contract Array(_ T) {
len(&T{})
}
append
accecpts only slices.
contract Slice(t T) {
append(t, t...)
}
delete
accepts only maps and key can get from for range
.
contract Map(t T) {
for k, _ := range t {
delete(t, k)
}
}
Just try to receive.
contract Receivable(t T) {
<-t
}
close
accepts only sendable channel.
contract Sendable(t T) {
close(t)
}
Operator *
accepts only poointers.
contract Pointer(t T) {
*t
}
contract NamedType(_ T) {
var _ struct {
T
}
}
contract NeqT1T2(_ T1, _ T2) {
var _ struct {
T1
T2
}
}
contract NotBuiltin(_ T) {
var _ struct {
int;int8;int16;int32;int64
uint;uint8;uint16;uint32;uint64
uintptr;byte;rune
float32;float64
complex64;complex128
string
bool
error
T
}
}
contract Deprecated(t T) {
type D struct{}
var _ D = t
}