dongshan1811 2015-03-17 16:10
浏览 28

为什么Go的io包中没有RuneWriter接口?

Go's io package contains (among others) the following interfaces:

type ByteReader interface {
        ReadByte() (c byte, err error)
}

type ByteScanner interface {
        ByteReader
        UnreadByte() error
}

type ByteWriter interface {
        WriteByte(c byte) error
}

type RuneReader interface {
        ReadRune() (r rune, size int, err error)
}

type RuneScanner interface {
        RuneReader
        UnreadRune() error
}

But there is no RuneWriter interface:

type RuneWriter interface {
        WriteRune(r rune) (size int, err error)
}

Is there a reason that RuneWriter is missing?

  • 写回答

2条回答 默认 最新

  • douquan3294 2015-03-17 20:41
    关注

    The Go authors define interfaces based on need. They do not define an interface for the purpose of filling out a grid of possible methods. This policy helps to keep the standard library small and simple.

    I think they concluded that there's little need for the the RuneWriter interface because they didn't need it in the standard packages or other packages that they maintain.

    There's been no demand for the interface outside of the Go team. There are no requests for the interface on the issue tracker, mail list, or the available recorded history for the irc channel.

    The other interfaces referenced in the question are used in the standard packages or other packages that the Go authors maintain.

    You can define the interface in your own package or code. This is a very useful feature that's somewhat unique to Go.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line