RuneReader interface

311 views
Skip to first unread message

Bob Appleyard

unread,
Oct 17, 2010, 8:54:43 PM10/17/10
to golang-nuts
I do a code search for ReadRune and I get

package bufio:
func (b *Reader) ReadRune() (rune int, size int, err os.Error)

package bytes:
func (b *Buffer) ReadRune() (r int, size int, err os.Error)

package fmt:
func (r *readRune) ReadRune() (rune int, size int, err os.Error)

package strings:
func (r *Reader) ReadRune() (rune int, size int, err os.Error)

I have found it useful, therefore, to issue the following:

type RuneReader interface {
ReadRune() (rune int, size int, err os.Error)
}

Why oh why is this not in the standard library somewhere? Or am I
missing something?

Andrew Gerrand

unread,
Oct 17, 2010, 9:10:18 PM10/17/10
to Bob Appleyard, golang-nuts, Rob Pike

That interface is defined privately in the fmt package
(src/pkg/fmt/scan,go). My guess as to why it's not public because it
hasn't seen use outside fmt yet. It could be made public, and, if so,
io might be a more suitable place than fmt.

With that said, there's nothing wrong or distasteful about defining
and using the interface type yourself.

Andrew

Bob Appleyard

unread,
Oct 17, 2010, 10:45:27 PM10/17/10
to golang-nuts
On Oct 18, 2:10 am, Andrew Gerrand <a...@golang.org> wrote:
> On 18 October 2010 11:54, Bob Appleyard <bob.appley...@gmail.com> wrote:
>
>
>
> > I do a code search for ReadRune and I get
>
> > package bufio:
> > func (b *Reader) ReadRune() (rune int, size int, err os.Error)
>
> > package bytes:
> > func (b *Buffer) ReadRune() (r int, size int, err os.Error)
>
> > package fmt:
> > func (r *readRune) ReadRune() (rune int, size int, err os.Error)
>
> > package strings:
> > func (r *Reader) ReadRune() (rune int, size int, err os.Error)
>
> > I have found it useful, therefore, to issue the following:
>
> > type RuneReader interface {
> >    ReadRune() (rune int, size int, err os.Error)
> > }
>
> > Why oh why is this not in the standard library somewhere? Or am I
> > missing something?
>
> That interface is defined privately in the fmt package
> (src/pkg/fmt/scan,go).

Ah yes, I see.

> My guess as to why it's not public because it
> hasn't seen use outside fmt yet. It could be made public,  and, if so,
> io might be a more suitable place than fmt.
>

I would agree.

Reply all
Reply to author
Forward
0 new messages