Documentation
¶
Overview ¶
Package conv provides a unified string parsing function. Think of it like the inverse of fmt.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse parses source unto dest, which must be settable. The type of data expected from source depends on the type of dest. This is determined as follows:
- If dest implements encoding.TextUnmarshaler, unmarshal using source[0].
- Try registered multi-value parsers
- If dest implements a function Store[T any](T), parse into a new destination of T and then call Store with the resulting value.
- Try composite types: - Array - Slice - Map (keys are used like a set, values are zeroed)
- Try registered single-value parsers.
- Try basic single values.
When parsing into a single value, one source string is expected. When parsing into an aggregate type such as a slice or map, each source will be parsed into a different element.
ParsePtr will be sufficient for most use cases, and it does not require importing the reflection package.
func Register ¶
Register registers a parser for a particular type.
Types ¶
type IndexError ¶ added in v0.5.0
type IndexError struct {
// Index is the index of the source.
Index int
// Err is the wrapped error.
Err error
}
IndexError is returned when an error occurrs while parsing a specific source.
func (IndexError) Error ¶ added in v0.5.0
func (this IndexError) Error() string
Error fulfills error.
func (IndexError) Unwrap ¶ added in v0.5.0
func (this IndexError) Unwrap() error
Unwrap returns Err.
Source Files
¶
- builtin.go
- conv.go