EDIT: On further thought, the implications of using iface.As
, e.g., for io.WriterTo
are quite subtle. If you were trying, say, to add logging to all Read
calls, you wouldn't want to simply pass through to the underlying io.WriterTo
because the call would go unlogged. Instead you'd need to implement the As
method on your type so as to only return a WriterTo
under certain conditions. Still, I think this idea is worth exploring more.
The Go 2 process has produced a proposal for extending the errors standard package, which is currently in testing.
My observation about the experimental errors package is: As() and Is() solve problems that exist well beyond the error interface.
Essentially the problem is this, many packages begin by requiring a certain interface, such as error
, io.Reader
, or