问题描述
指出:
bufio.io
包包含:
// Reader为io.Reader对象实现缓冲。
类型Reader结构{
buf []字节
rd io.Reader
r,w int
err错误
lastByte int
lastRuneSize int
它是否具有像* er这样的结构?特别是在这种情况下,它是一个 struct
,与 io.Reader
是同一个接口。
评论很重要:
// 既然 从用户的角度来看,它是一个 The "Effective Go" states: Is it idiomatic having structs named like "*er"? Especially in this case it's a The comment // The bufio packages adds: Since For the user's point of view, it is a 这篇关于它是否具有非接口称为“* er”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! Reader
为
io.Reader
对象实现缓冲。 bufio.Reader
没有添加任何新服务,但只是以缓冲方式实现 io.Reader
,保留名称并仅实现函数是有意义的:a struct
就足够了。
Reader
,他/她可以在需要io.Reader的地方使用。bufio.io
package contains this:// Reader implements buffering for an io.Reader object.
type Reader struct {
buf []byte
rd io.Reader
r, w int
err error
lastByte int
lastRuneSize int
}
struct
with the same name as io.Reader
which is an interface.type bufio.Reader struct
are important:Reader
implements buffering for an io.Reader
object.bufio.Reader
isn't there to add any new service, but only to implements an io.Reader
in a buffered way, it makes sense to keep the name and just implement the functions: a struct
is enough.Reader
that he/she can uses wherever an io.Reader is required.