zstdzgo.at/zstd/ztype Index | Files

package ztype

import "zgo.at/zstd/ztype"

Package ztype adds extra types.

Index

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

func NewOptional[V any](v V) Optional[V]

NewOptional creates a new Optional for the given value.

func (Optional[V]) Get

func (o Optional[V]) Get() (V, bool)

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 (o Optional[V]) MarshalJSON() ([]byte, error)

func (*Optional[V]) Scan

func (o *Optional[V]) Scan(v any) error

func (*Optional[V]) Set

func (o *Optional[V]) Set(v V)

Set a value.

func (Optional[V]) String

func (o Optional[V]) String() string

func (*Optional[V]) UnmarshalJSON

func (o *Optional[V]) UnmarshalJSON(data []byte) error

func (*Optional[V]) Unset

func (o *Optional[V]) Unset()

Unset this optional.

func (Optional[V]) Value

func (o Optional[V]) Value() (driver.Value, error)

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.