package ztype
import "zgo.at/zstd/ztype"
Package ztype adds extra types.
Index ¶
- func Deref[T any](v *T, dv T) T
- func Ptr[T any](t T) *T
- func PtrOrNil[T any](t T) *T
- type Optional
- func NewOptional[V any](v V) Optional[V]
- func (o Optional[V]) Get() (V, bool)
- func (o Optional[V]) MarshalJSON() ([]byte, error)
- func (o *Optional[V]) Scan(v any) error
- func (o *Optional[V]) Set(v V)
- func (o Optional[V]) String() string
- func (o *Optional[V]) UnmarshalJSON(data []byte) error
- func (o *Optional[V]) Unset()
- func (o Optional[V]) Value() (driver.Value, error)
Functions ¶
func Deref ¶
func Deref[T any](v *T, dv T) T
Deref dereferences the pointer v, returning dv if it's nil.
func Ptr ¶
func Ptr[T any](t T) *T
Ptr gets a pointer to t.
func PtrOrNil ¶
func PtrOrNil[T any](t T) *T
PtrOrNil gets a pointer to t, or nil if t is the zero value.
Types ¶
type Optional ¶
type Optional[V any] struct { // contains filtered or unexported fields }
Optional represents a value that may or may not exist.
The zero value represents a non-existent value.
type Strukt struct { Value zstd.Optional[int] } s := Struct{ Value: zstd.NewOptional[] } if v, ok := s.Value.Get(); ok { }
func NewOptional ¶
NewOptional creates a new Optional for the given value.
func (Optional[V]) Get ¶
Get the value and a flag indicating if it was set.
The returned value is undefined if it's not set; it can be the type zero value, nil, or anything else.
func (Optional[V]) MarshalJSON ¶
func (*Optional[V]) Scan ¶
func (*Optional[V]) Set ¶
func (o *Optional[V]) Set(v V)
Set a value.
func (Optional[V]) String ¶
func (*Optional[V]) UnmarshalJSON ¶
func (*Optional[V]) Unset ¶
func (o *Optional[V]) Unset()
Unset this optional.
func (Optional[V]) Value ¶
Source Files ¶
optional.go ztype.go
- Version
- v0.0.0-20240930202209-a63c3335042a (latest)
- Published
- Sep 30, 2024
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 2 days ago –
Tools for package owners.