Standard library / fmt
fmt.Scanner
Scan implements custom scanning for an operand; receives scanner state and verb and returns an error. Copy token bytes if retaining them after the call. Expected stdout: '1 alpha <nil>\n'.
Formal Syntax & Structure
go syntaxgo
type Scanner interface { Scan(state ScanState, verb rune) error }Working Example
Example Snippetgo
package main
import ( "fmt")
type label string
func (l *label) Scan(s fmt.ScanState, v rune) error { b, e := s.Token(true, nil) if e == nil { *l = label(string(b)) } return e}func main() { var l label n, e := fmt.Sscan("alpha", &l) fmt.Println(n, l, e)}