Standard library / fmt

fmt.ScanState

Provides rune reading/unreading, whitespace skipping, token extraction, width and Read to custom Scanner implementations. Token may reference reused storage. Expected stdout: 'hello <nil>\n'.

Formal Syntax & Structure

go syntaxgo
type ScanState interface { ReadRune() (r rune, size int, err error); UnreadRune() error; SkipSpace(); Token(skipSpace bool, f func(rune) bool) (token []byte, err error); Width() (wid int, ok bool); Read(buf []byte) (n int, err error) }

Working Example

Example Snippetgo
package main
import (  "fmt")
type probe string
func (p *probe) Scan(s fmt.ScanState, v rune) error {  b, e := s.Token(true, nil)  if e == nil {    *p = probe(string(b))  }  return e}func main() {  var p probe  _, e := fmt.Sscan("hello", &p)  fmt.Println(p, e)}
Go Reference