ztype

package
v0.0.0-...-49fafbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package ztype adds extra types.

Index

Constants

This section is empty.

Variables

This section is empty.

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL