sqlite
sqlite copied to clipboard
Blob struct should not have io interfaces as fields
https://github.com/crawshaw/sqlite/blob/6c1d4ad4ed9d0acc0ca4b99dd67c5c14d488633c/blob.go#L81-L85
This code defines a struct with fields named ReadWriteSeeker
, ReaderAt
, WriterAt
, and Closer
which are never used. Notably, Blob
itself implements the functions required by these interfaces. If Blob
was an interface this syntax would mean that whatever implements Blob
must have the methods in the listed interfaces, but written as a struct this syntax defines four separate fields in the struct itself. This appears to be a mistake.
Here's a playground example that shows this: https://go.dev/play/p/Hr0SlKqYhV9
To require that a struct Blob
implements the required interfaces, one can use the "interface guards" pattern like this:
var _ io.ReadWriteSeeker = &Blob{}
var _ io.ReaderAt = &Blob{}
var _ io.WriterAt = &Blob{}
var _ io.Closer = &Blob{}