Documentation ¶
Index ¶
- type Conversions
- type Converter
- type Option
- func With[T comparable, D any](opts ...Option[T, D]) Option[T, D]
- func WithConversion[T comparable, D any](from T, to T, conv Converter[D]) Option[T, D]
- func WithTypeExtractor[T comparable, D any](extractor func(D) (T, error)) Option[T, D]
- func WithTypedConversion[T comparable, D any](conv TypedConversion[T, D]) Option[T, D]
- type TypedConversion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conversions ¶
type Conversions[T comparable, D any] struct { // contains filtered or unexported fields }
Conversions contains converters between different types.
func New ¶
func New[T comparable, D any](opts ...Option[T, D]) (*Conversions[T, D], error)
New creates a new Conversions instance.
func (*Conversions[T, D]) AddConversion ¶
func (c *Conversions[T, D]) AddConversion(from T, to T, conv Converter[D])
AddConversion adds a new converter to the conversions.
func (*Conversions[T, D]) Convert ¶
func (c *Conversions[T, D]) Convert(value D, to T) (any, error)
Convert converts a value from one type to another.
type Option ¶
type Option[T comparable, D any] func(*options[T, D]) error
Option represents an option for Conversions.
func With ¶
func With[T comparable, D any](opts ...Option[T, D]) Option[T, D]
With combines multiple options into a single option.
func WithConversion ¶
func WithConversion[T comparable, D any](from T, to T, conv Converter[D]) Option[T, D]
WithConversion makes a conversion available for use.
func WithTypeExtractor ¶
func WithTypeExtractor[T comparable, D any](extractor func(D) (T, error)) Option[T, D]
WithTypeExtractor sets the type extractor to use when converting values. The type extractor is asked to extract the type of a value, the type is then used to find suitable conversions.
func WithTypedConversion ¶
func WithTypedConversion[T comparable, D any](conv TypedConversion[T, D]) Option[T, D]
WithTypedConversion makes a typed conversion available for use.
type TypedConversion ¶
type TypedConversion[T comparable, D any] struct { // From is the type that the converter can convert from. From T // To is the type that the converter can convert to. To T // Converter is the converter function. Converter Converter[D] }
TypedConversion represents a conversion between two types. It extends Converter with the types that the converter can convert between.