github.com/itsabgr/go-handy@v0.0.0-20220724000257-022d51f2b9c6/cast.go (about)

     1  package handy
     2  
     3  import "fmt"
     4  
     5  //Cast [T any] casts interface{} to T
     6  func Cast[T any](t interface{}) T {
     7  	switch t.(type) {
     8  	case T:
     9  		return t.(T)
    10  	}
    11  	panic(fmt.Errorf("unexpected type %T", t))
    12  }