Remove Implements
This commit is contained in:
parent
816e3846a4
commit
a1706cf168
@ -194,12 +194,6 @@ func Has(s interface{}, fieldName string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements returns true if the given struct s implements the i interface
|
|
||||||
// type.
|
|
||||||
func Implements(s, i interface{}) bool {
|
|
||||||
return reflect.TypeOf(s).Implements(reflect.TypeOf(i).Elem())
|
|
||||||
}
|
|
||||||
|
|
||||||
// strctInfo returns the struct value and the exported struct fields for a
|
// strctInfo returns the struct value and the exported struct fields for a
|
||||||
// given s struct. This is a convenient helper method to avoid duplicate code
|
// given s struct. This is a convenient helper method to avoid duplicate code
|
||||||
// in some of the functions.
|
// in some of the functions.
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package structure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -147,28 +146,3 @@ func ExampleHas() {
|
|||||||
// Output:
|
// Output:
|
||||||
// Has: true
|
// Has: true
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bar struct{}
|
|
||||||
|
|
||||||
func (b Bar) String() string { return "bar" }
|
|
||||||
func (b Bar) Write(p []byte) (n int, err error) { return 0, nil }
|
|
||||||
|
|
||||||
func ExampleImplements() {
|
|
||||||
// type Bar struct{}
|
|
||||||
//
|
|
||||||
// func (b Bar) String() string { return "bar" }
|
|
||||||
// func (b Bar) Write(p []byte) (n int, err error) { return 0, nil }
|
|
||||||
b := Bar{}
|
|
||||||
|
|
||||||
okA := Implements(b, new(fmt.Stringer))
|
|
||||||
okB := Implements(b, new(io.Writer))
|
|
||||||
okC := Implements(b, new(io.Reader))
|
|
||||||
|
|
||||||
fmt.Printf("Implements io.Writer: %+v\n", okA)
|
|
||||||
fmt.Printf("Implements io.Reader: %+v\n", okB)
|
|
||||||
fmt.Printf("Implements fmt.Stringer: %+v\n", okC)
|
|
||||||
// Output:
|
|
||||||
// Implements io.Writer: true
|
|
||||||
// Implements io.Reader: true
|
|
||||||
// Implements fmt.Stringer: false
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package structure
|
package structure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -473,17 +471,3 @@ func TestName(t *testing.T) {
|
|||||||
t.Error("Name should return empty string for unnamed struct, got: %s", n)
|
t.Error("Name should return empty string for unnamed struct, got: %s", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Foo struct{}
|
|
||||||
|
|
||||||
func (f Foo) String() string { return "foo" }
|
|
||||||
func (f Foo) Write(p []byte) (n int, err error) { return 0, nil }
|
|
||||||
|
|
||||||
func TestImplements(t *testing.T) {
|
|
||||||
f := Foo{}
|
|
||||||
|
|
||||||
ok := Implements(f, new(io.Reader))
|
|
||||||
|
|
||||||
fmt.Printf("ok %+v\n", ok)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user