scanner

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Example (CreateArrayScanner)
var ints [3]int
c := NewCreator()
scan, err := c.createArrayScanner(reflect.TypeOf(ints))

if err != nil {
	panic(err)
}

if err = scan(unsafe.Pointer(&ints), "123,456,789,999,,,,"); err != nil {
	panic(err)
}

fmt.Println("values:", ints)
Output:

values: [123 456 789]
Example (CreatePointerScanner)
var foo *int

c := NewCreator()
scan, err := c.createPointerScanner(reflect.TypeOf(foo))

if err != nil {
	panic(err)
}

// Pointer to a pointer
if err = scan(unsafe.Pointer(&foo), "123"); err != nil {
	panic(err)
}

fmt.Println(*foo)

// Pointer to a pointer
if err = scan(unsafe.Pointer(&foo), "456"); err != nil {
	panic(err)
}

fmt.Println(*foo)
Output:


123
456
Example (CreateSliceScanner)
var ints []int

c := NewCreator()
scan, err := c.createSliceScanner(reflect.TypeOf(ints))

if err != nil {
	panic(err)
}

if err = scan(unsafe.Pointer(&ints), "123,456,789"); err != nil {
	panic(err)
}

fmt.Println("cap:", cap(ints))
fmt.Println("len:", len(ints))
fmt.Println("values:", ints)
Output:


cap: 3
len: 3
values: [123 456 789]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetScanner

func GetScanner[T any](dst *T) (scan func(*T, string) error, err error)

func ScanBytes

func ScanBytes[T any](dst *T, src []byte) (err error)

func ScanString

func ScanString[T any](dst *T, src string) (err error)

Types

type Creator

type Creator struct {
	// contains filtered or unexported fields
}

func NewCreator

func NewCreator(custom ...func(typ reflect.Type) (Scanner, error)) Creator

func (Creator) CreateScanner

func (c Creator) CreateScanner(typ reflect.Type) (scan Scanner, err error)

type Scanner

type Scanner func(unsafe.Pointer, string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL