Documentation
¶
Overview ¶
Package null provides generic nullable types.
Provided types are compatible with encoding/json (json.Marshaler and json.Unmarshaler) and sql/database (sql.Scanner and driver.Valuer)
Index ¶
- type Type
- func (s *Type[T]) CheckedValue() (T, bool)
- func (s *Type[T]) CheckedValuePtr() (*T, bool)
- func (s *Type[T]) DefaultValue() T
- func (s *Type[T]) IsNull() bool
- func (s *Type[T]) RawValue() T
- func (s *Type[T]) RawValuePtr() *T
- func (s *Type[T]) SetNull()
- func (s *Type[T]) SetValue(v T)
- func (s *Type[T]) SetValueFromPtr(valuePtr *T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Type ¶
type Type[T any] struct { // contains filtered or unexported fields }
Type represents a nullable type. Default value is null.
func ValueFromPtr ¶ added in v1.2.1
ValueFromPtr returns null Type if valuePtr is nil, Type with actual value otherwise.
func (*Type[T]) CheckedValue ¶ added in v1.2.0
CheckedValue returns actual value and true if Type is not null, default value of T and false otherwise.
func (*Type[T]) CheckedValuePtr ¶ added in v1.2.0
CheckedValuePtr returns pointer to actual value and true if Type is not null, false otherwise
func (*Type[T]) DefaultValue ¶ added in v1.2.0
func (s *Type[T]) DefaultValue() T
DefaultValue returns default value of T
func (*Type[T]) RawValue ¶
func (s *Type[T]) RawValue() T
RawValue returns actual value if Type is not null, default value of T otherwise.
func (*Type[T]) RawValuePtr ¶ added in v1.2.0
func (s *Type[T]) RawValuePtr() *T
RawValuePtr returns pointer to actual value. Is useful only when Type is not null
func (*Type[T]) SetValueFromPtr ¶ added in v1.2.0
func (s *Type[T]) SetValueFromPtr(valuePtr *T)
SetValueFromPtr sets Type to not null value if valuePtr is not nil, null value otherwise.