Documentation ¶
Overview ¶
Package writer provides writers
SPDX-License-Identifier: Apache-2.0
Index ¶
- func IOWriterAsLinesGen(dst io.Writer) func(string) error
- func IOWriterAsRunesGen(dst io.Writer) func(rune) error
- func IOWriterAsStringsGen(dst io.Writer) func(string) error
- func IOWriterGen(dst io.Writer) func(byte) error
- func MapWriterGen[K comparable, V any](m map[K]V) func(tuple.Two[K, V]) error
- func SliceWriterGen[T any](slc *[]T) func(T) error
- type Writer
- func NewWriter[T any](writerFn func(T) error) Writer[T]
- func OfIOWriterAsBytes(dst io.Writer) Writer[byte]
- func OfIOWriterAsLines(dst io.Writer) Writer[string]
- func OfIOWriterAsRunes(dst io.Writer) Writer[rune]
- func OfIOWriterAsStrings(dst io.Writer) Writer[string]
- func OfMapWriter[K comparable, V any](dst map[K]V) Writer[tuple.Two[K, V]]
- func OfSliceWriter[T any](dst *[]T) Writer[T]
- type WriterImpl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IOWriterAsLinesGen ¶
IOWriterAsLinesGen generates a writing function for writing lines to an io.Writer. The idea is that each string is one line, but does not end in any line ending sequence. The OS line ending sequence is used. Returns an error if any rune is not written: - If the Writer returns an error, it is returned as is - If the Writer wrote fewer bytes than the UTF-8 encoding requires, a custom error containing the number of bytes written is returned
func IOWriterAsRunesGen ¶
IOWriterAsRunesGen generates a writing function for writing runes to an io.Writer. Returns an error if the rune is not written: - If the Writer returns an error, it is returned as is - If the Writer wrote fewer bytes than the UTF-8 encoding requires, a custom error containing the hex value of the rune is returned
func IOWriterAsStringsGen ¶
IOWriterAsStringsGen generates a writing function for writing strings to an io.Writer. Returns an error if any rune is not written: - If the Writer returns an error, it is returned as is - If the Writer wrote fewer bytes than the UTF-8 encoding requires, a custom error containing the number of bytes written is returned
func IOWriterGen ¶
IOWriterGen generates a writing function for writing bytes to an io.Writer. Returns an error if the byte is not written: - If the Writer returns an error, it is returned as is - If the Writer wrote 0 bytes with no error, an custom error containing the hex value of the byte is returned
func MapWriterGen ¶
func MapWriterGen[K comparable, V any](m map[K]V) func(tuple.Two[K, V]) error
MapWriterGen generates a writing function for a map[K]V. A pointer to the map is not required, as the map internally reallocates as needed, so that the caller map address never changes.
func SliceWriterGen ¶
SliceWritergen generates a writing function for a slice of type T. A pointer to the slice is required so that if the slice has to be reallocated, the address of the caller slice can be changed.
Types ¶
type Writer ¶
Writer defines a single method for writing zero or more values of type T to some destination. Returns an error if any value of type T cannot be written to the destination successfully. The error object contains whatever value the underlying storage function provides that could not be written.
func NewWriter ¶
NewWriter constructs a Writer[T] from a writing function that accepts T and returns error. Panics if writerFn is nil.
func OfIOWriterAsBytes ¶
OfIOWriterAsBytes returns a Writer[byte] that writes bytes to the given io.Writer. Panics if writing a byte fails.
func OfIOWriterAsLines ¶
OfIOWriterAsLines returns a Writer[string] that writes UTF-8 encoded strings to the given io.Writer. Each string is followed by the OS line ending sequence, where Windows uses CRLF and all other systems use LF. Panics if writing any byte of the string fails.
func OfIOWriterAsRunes ¶
OfIOWriterAsRunes returns a Writer[rune] that writes UTF-8 encoded runes to the given io.Writer. Panics if writing any byte of a rune fails.
func OfIOWriterAsStrings ¶
OfIOWriterAsStrings returns a Writer[string] that writes UTF-8 encoded strings to the given io.Writer. Panics if writing any byte of the string fails.
func OfMapWriter ¶
func OfMapWriter[K comparable, V any](dst map[K]V) Writer[tuple.Two[K, V]]
OfMapWriter returns a Writer[tuple.Two[K, V]] that writes to the given map
func OfSliceWriter ¶
OfSliceWriter returns a Writer[T] that writes to the given slice
type WriterImpl ¶
type WriterImpl[T any] struct { // contains filtered or unexported fields }
WriterImpl is the base implementation of Writer[T]
func (WriterImpl[T]) Write ¶
func (w WriterImpl[T]) Write(vals ...T) error
Write returns nil unless the value given cannot be written to the destination.