views
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package views provides read-only accessors for commonly usedvalue types.
Index¶
- func AppendStrings[T fmt.Stringer](dst []string, v Slice[T]) []string
- func ContainsPointers[T any]() bool
- func MapViewsEqual[K, V comparable](a, b Map[K, V]) bool
- func MapViewsEqualFunc[K comparable, V1, V2 any](a Map[K, V1], b Map[K, V2], eq func(V1, V2) bool) bool
- func SliceContains[T comparable](v Slice[T], e T) bool
- func SliceEqual[T comparable](a, b Slice[T]) bool
- func SliceEqualAnyOrder[T comparable](a, b Slice[T]) bool
- func SliceEqualAnyOrderFunc[T any, V comparable](a, b Slice[T], cmp func(T) V) bool
- func SliceMax[T cmp.Ordered](v Slice[T]) T
- func SliceMin[T cmp.Ordered](v Slice[T]) T
- type ByteSlice
- func (v ByteSlice[T]) AppendTo(dst T) T
- func (v ByteSlice[T]) AsSlice() T
- func (v ByteSlice[T]) At(i int) byte
- func (v ByteSlice[T]) Equal(b T) bool
- func (v ByteSlice[T]) EqualView(b ByteSlice[T]) bool
- func (v ByteSlice[T]) IsNil() bool
- func (v ByteSlice[T]) Len() int
- func (v ByteSlice[T]) MapKey() SliceMapKey[byte]
- func (v ByteSlice[T]) MarshalJSON() ([]byte, error)
- func (v ByteSlice[T]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (v ByteSlice[T]) Mem() mem.RO
- func (v ByteSlice[T]) Slice(i, j int) ByteSlice[T]
- func (v ByteSlice[T]) SliceFrom(i int) ByteSlice[T]
- func (v ByteSlice[T]) SliceTo(i int) ByteSlice[T]
- func (v *ByteSlice[T]) UnmarshalJSON(b []byte) error
- func (v *ByteSlice[T]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type Cloner
- type Map
- func (m Map[K, V]) All() iter.Seq2[K, V]
- func (m Map[K, V]) AsMap() map[K]V
- func (m Map[K, V]) Contains(k K) bool
- func (m Map[K, V]) Get(k K) V
- func (m Map[K, V]) GetOk(k K) (V, bool)
- func (m Map[K, V]) Has(k K) bool
- func (m Map[K, V]) IsNil() bool
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) MarshalJSON() ([]byte, error)
- func (m Map[K, V]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (m *Map[K, V]) UnmarshalJSON(b []byte) error
- func (m *Map[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type MapFn
- type MapRangeFn
- type MapSlice
- func (m MapSlice[K, V]) All() iter.Seq2[K, Slice[V]]
- func (m MapSlice[K, V]) AsMap() map[K][]V
- func (m MapSlice[K, V]) Contains(k K) bool
- func (m MapSlice[K, V]) Get(k K) Slice[V]
- func (m MapSlice[K, V]) GetOk(k K) (Slice[V], bool)
- func (m MapSlice[K, V]) IsNil() bool
- func (m MapSlice[K, V]) Len() int
- func (m MapSlice[K, V]) MarshalJSON() ([]byte, error)
- func (m MapSlice[K, V]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (m *MapSlice[K, V]) UnmarshalJSON(b []byte) error
- func (m *MapSlice[K, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type Slice
- func (v Slice[T]) All() iter.Seq2[int, T]
- func (v Slice[T]) AppendTo(dst []T) []T
- func (v Slice[T]) AsSlice() []T
- func (v Slice[T]) At(i int) T
- func (v Slice[T]) ContainsFunc(f func(T) bool) bool
- func (v Slice[T]) IndexFunc(f func(T) bool) int
- func (v Slice[T]) IsNil() bool
- func (v Slice[T]) Len() int
- func (v Slice[T]) MapKey() SliceMapKey[T]
- func (v Slice[T]) MarshalJSON() ([]byte, error)
- func (v Slice[T]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (v Slice[T]) MaxFunc(cmp func(a, b T) int) T
- func (v Slice[T]) MinFunc(cmp func(a, b T) int) T
- func (v Slice[T]) Slice(i, j int) Slice[T]
- func (v Slice[T]) SliceFrom(i int) Slice[T]
- func (v Slice[T]) SliceTo(i int) Slice[T]
- func (v *Slice[T]) UnmarshalJSON(b []byte) error
- func (v *Slice[T]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type SliceMapKey
- type SliceView
- func (v SliceView[T, V]) All() iter.Seq2[int, V]
- func (v SliceView[T, V]) AppendTo(dst []V) []V
- func (v SliceView[T, V]) AsSlice() []V
- func (v SliceView[T, V]) At(i int) V
- func (v SliceView[T, V]) IsNil() bool
- func (v SliceView[T, V]) Len() int
- func (v SliceView[T, V]) MapKey() SliceMapKey[T]
- func (v SliceView[T, V]) MarshalJSON() ([]byte, error)
- func (v SliceView[T, V]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (v SliceView[T, V]) Slice(i, j int) SliceView[T, V]
- func (v SliceView[T, V]) SliceFrom(i int) SliceView[T, V]
- func (v SliceView[T, V]) SliceTo(i int) SliceView[T, V]
- func (v *SliceView[T, V]) UnmarshalJSON(b []byte) error
- func (v *SliceView[T, V]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- type StructView
- type ValuePointer
- func (p ValuePointer[T]) Clone() *T
- func (p ValuePointer[T]) Get() T
- func (p ValuePointer[T]) GetOk() (value T, ok bool)
- func (p ValuePointer[T]) GetOr(def T) T
- func (p ValuePointer[T]) MarshalJSON() ([]byte, error)
- func (p ValuePointer[T]) MarshalJSONTo(enc *jsontext.Encoder) error
- func (p ValuePointer[T]) String() string
- func (p *ValuePointer[T]) UnmarshalJSON(b []byte) error
- func (p *ValuePointer[T]) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (p ValuePointer[T]) Valid() bool
- type ViewCloner
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcAppendStrings¶added inv1.66.0
AppendStrings appends the string representation of each element in v to dst.
funcContainsPointers¶added inv1.72.0
ContainsPointers reports whether T contains any pointers,either explicitly or implicitly.It has special handling for some types that contain pointersthat we know are free from memory aliasing/mutation concerns.
funcMapViewsEqual¶added inv1.80.0
func MapViewsEqual[K, Vcomparable](a, bMap[K, V])bool
MapViewsEqual returns whether the two given [Map]s are equal. Both K and Vmust be comparable; if V is non-comparable, useMapViewsEqualFunc instead.
funcMapViewsEqualFunc¶added inv1.80.0
MapViewsEqualFunc returns whether the two given [Map]s are equal, using thegiven function to compare two values.
funcSliceContains¶added inv1.30.0
func SliceContains[Tcomparable](vSlice[T], e T)bool
SliceContains reports whether v contains element e.
As it runs in O(n) time, use with care.
funcSliceEqual¶added inv1.50.0
func SliceEqual[Tcomparable](a, bSlice[T])bool
SliceEqual is like the standard library's slices.Equal, but for two views.
funcSliceEqualAnyOrder¶added inv1.36.0
func SliceEqualAnyOrder[Tcomparable](a, bSlice[T])bool
SliceEqualAnyOrder reports whether a and b contain the same elements, regardless of order.The underlying slices for a and b can be nil.
funcSliceEqualAnyOrderFunc¶added inv1.80.0
func SliceEqualAnyOrderFunc[Tany, Vcomparable](a, bSlice[T], cmp func(T) V)bool
SliceEqualAnyOrderFunc reports whether a and b contain the same elements,regardless of order. The underlying slices for a and b can be nil.
The provided function should return a comparable value for each element.
funcSliceMax¶added inv1.88.0
SliceMax returns the maximal value in v. It panics if v is empty. Forfloating point T, SliceMax propagates NaNs (any NaN value in v forces theoutput to be NaN). See alsoslices.Max.
Types¶
typeByteSlice¶added inv1.50.0
type ByteSlice[T ~[]byte] struct {// contains filtered or unexported fields}
ByteSlice is a read-only accessor for types that are backed by a []byte.
funcByteSliceOf¶added inv1.50.0
ByteSliceOf returns a ByteSlice for the provided slice.
func (ByteSlice[T])AppendTo¶added inv1.50.0
func (vByteSlice[T]) AppendTo(dst T) T
AppendTo appends the underlying slice values to dst.
func (ByteSlice[T])AsSlice¶added inv1.50.0
func (vByteSlice[T]) AsSlice() T
AsSlice returns a copy of the underlying slice.
func (ByteSlice[T])EqualView¶added inv1.50.0
EqualView reports whether the underlying slice is equal to b.
func (ByteSlice[T])MapKey¶added inv1.60.0
func (vByteSlice[T]) MapKey()SliceMapKey[byte]
MapKey returns a unique key for a slice, based on its address and length.
func (ByteSlice[T])MarshalJSON¶added inv1.50.0
MarshalJSON implementsjsonv1.Marshaler.
func (ByteSlice[T])MarshalJSONTo¶added inv1.88.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*ByteSlice[T])UnmarshalJSON¶added inv1.50.0
UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized ByteSlice.
func (*ByteSlice[T])UnmarshalJSONFrom¶added inv1.88.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized ByteSlice.
typeCloner¶added inv1.72.0
type Cloner[Tany] interface {// Clone returns a deep-clone of the receiver.// It returns nil, when the receiver is nil.Clone() T}
Cloner is any type that has a Clone function returning a deep-clone of the receiver.
typeMap¶added inv1.26.0
type Map[Kcomparable, Vany] struct {// contains filtered or unexported fields}
Map provides a read-only view of a map. It is the caller's responsibility tomake sure V is immutable.
funcMapOf¶added inv1.26.0
func MapOf[Kcomparable, Vany](m map[K]V)Map[K, V]
MapOf returns a view over m. It is the caller's responsibility to make sure Vis immutable.
func (Map[K, V])AsMap¶added inv1.46.0
func (mMap[K, V]) AsMap() map[K]V
AsMap returns a shallow-clone of the underlying map.If V is a pointer type, it is the caller's responsibility to make surethe values are immutable.
func (Map[K, V])GetOk¶added inv1.26.0
GetOk returns the element with key k and a bool representing whether the keyis in map.
func (Map[K, V])Has¶added inv1.26.0
Has reports whether k has an entry in the map.Deprecated: use Contains instead.
func (Map[K, V])MarshalJSON¶added inv1.46.0
MarshalJSON implementsjsonv1.Marshaler.
func (Map[K, V])MarshalJSONTo¶added inv1.88.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*Map[K, V])UnmarshalJSON¶added inv1.46.0
UnmarshalJSON implementsjsonv1.Unmarshaler.It should only be called on an uninitialized Map.
func (*Map[K, V])UnmarshalJSONFrom¶added inv1.88.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized Map.
typeMapFn¶added inv1.26.0
type MapFn[Kcomparable, Tany, Vany] struct {// contains filtered or unexported fields}
MapFn is like Map but with a func to convert values from T to V.It is used to provide map of slices and views.
funcMapFnOf¶added inv1.26.0
func MapFnOf[Kcomparable, Tany, Vany](m map[K]T, f func(T) V)MapFn[K, T, V]
MapFnOf returns a MapFn for m.
func (MapFn[K, T, V])All¶added inv1.76.0
All returns an iterator iterating over the keys and value views of m.
func (MapFn[K, T, V])Get¶added inv1.26.0
func (mMapFn[K, T, V]) Get(k K) V
Get returns the element with key k.
func (MapFn[K, T, V])GetOk¶added inv1.26.0
GetOk returns the element with key k and a bool representing whether the keyis in map.
func (MapFn[K, T, V])Has¶added inv1.26.0
Has reports whether k has an entry in the map.Deprecated: use Contains instead.
typeMapRangeFn¶added inv1.26.0
type MapRangeFn[Kcomparable, Vany] func(k K, v V) (contbool)
MapRangeFn is the func called from a Map.Range call.Implementations should return false to stop range.
typeMapSlice¶added inv1.70.0
type MapSlice[Kcomparable, Vany] struct {// contains filtered or unexported fields}
MapSlice is a view over a map whose values are slices.
funcMapSliceOf¶added inv1.70.0
func MapSliceOf[Kcomparable, Vany](m map[K][]V)MapSlice[K, V]
MapSliceOf returns a MapSlice for the provided map. It is the caller'sresponsibility to make sure V is immutable.
func (MapSlice[K, V])All¶added inv1.76.0
All returns an iterator iterating over the keys and values of m.
func (MapSlice[K, V])AsMap¶added inv1.70.0
func (mMapSlice[K, V]) AsMap() map[K][]V
AsMap returns a shallow-clone of the underlying map.
If V is a pointer type, it is the caller's responsibility to make sure thevalues are immutable. The map and slices are cloned, but the values are not.
func (MapSlice[K, V])GetOk¶added inv1.70.0
GetOk returns the element with key k and a bool representing whether the keyis in map.
func (MapSlice[K, V])MarshalJSON¶added inv1.70.0
MarshalJSON implementsjsonv1.Marshaler.
func (MapSlice[K, V])MarshalJSONTo¶added inv1.88.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*MapSlice[K, V])UnmarshalJSON¶added inv1.70.0
UnmarshalJSON implementsjsonv1.Unmarshaler.It should only be called on an uninitialized Map.
func (*MapSlice[K, V])UnmarshalJSONFrom¶added inv1.88.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It should only be called on an uninitialized MapSlice.
typeSlice¶added inv1.24.0
type Slice[Tany] struct {// contains filtered or unexported fields}
Slice is a read-only accessor for a slice.
funcSliceOf¶added inv1.24.0
SliceOf returns a Slice for the provided slice for immutable values.It is the caller's responsibility to make sure V is immutable.
func (Slice[T])AppendTo¶added inv1.24.0
func (vSlice[T]) AppendTo(dst []T) []T
AppendTo appends the underlying slice values to dst.
func (Slice[T])AsSlice¶added inv1.24.0
func (vSlice[T]) AsSlice() []T
AsSlice returns a copy of underlying slice.
func (Slice[T])ContainsFunc¶added inv1.30.0
ContainsFunc reports whether any element in v satisfies f(e).
As it runs in O(n) time, use with care.
func (Slice[T])IndexFunc¶added inv1.30.0
IndexFunc returns the first index of an element in v satisfying f(e),or -1 if none do.
As it runs in O(n) time, use with care.
func (Slice[T])MapKey¶added inv1.60.0
func (vSlice[T]) MapKey()SliceMapKey[T]
MapKey returns a unique key for a slice, based on its address and length.
func (Slice[T])MarshalJSON¶added inv1.24.0
MarshalJSON implementsjsonv1.Marshaler.
func (Slice[T])MarshalJSONTo¶added inv1.88.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (Slice[T])MaxFunc¶added inv1.88.0
MaxFunc returns the maximal value in v, using cmp to compare elements. Itpanics if v is empty. If there is more than one maximal element according tothe cmp function, MaxFunc returns the first one. See alsoslices.MaxFunc.
func (Slice[T])MinFunc¶added inv1.88.0
MinFunc returns the minimal value in v, using cmp to compare elements. Itpanics if v is empty. If there is more than one minimal element according tothe cmp function, MinFunc returns the first one. See alsoslices.MinFunc.
func (*Slice[T])UnmarshalJSON¶added inv1.24.0
UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized Slice.
func (*Slice[T])UnmarshalJSONFrom¶added inv1.88.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized Slice.
typeSliceMapKey¶added inv1.60.0
type SliceMapKey[Tany] struct {// contains filtered or unexported fields}
SliceMapKey represents a comparable unique key for a slice, based on itsaddress and length. It can be used to key maps by slices but should only beused when the underlying slice is immutable.
Empty and nil slices have different keys.
typeSliceView¶added inv1.26.0
type SliceView[TViewCloner[T, V], VStructView[T]] struct {// contains filtered or unexported fields}
SliceView wraps []T to provide accessors which return an immutable view V ofT. It is used to provide the equivalent of SliceOf([]V) without having toallocate []V from []T.
funcSliceOfViews¶added inv1.26.0
func SliceOfViews[TViewCloner[T, V], VStructView[T]](x []T)SliceView[T, V]
SliceOfViews returns a ViewSlice for x.
func (SliceView[T, V])AppendTo¶added inv1.26.0
func (vSliceView[T, V]) AppendTo(dst []V) []V
AppendTo appends the underlying slice values to dst.
func (SliceView[T, V])AsSlice¶added inv1.26.0
func (vSliceView[T, V]) AsSlice() []V
AsSlice returns a copy of underlying slice.
func (SliceView[T, V])MapKey¶added inv1.60.0
func (vSliceView[T, V]) MapKey()SliceMapKey[T]
MapKey returns a unique key for a slice, based on its address and length.
func (SliceView[T, V])MarshalJSON¶added inv1.26.0
MarshalJSON implementsjsonv1.Marshaler.
func (SliceView[T, V])MarshalJSONTo¶added inv1.88.0
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (*SliceView[T, V])UnmarshalJSON¶added inv1.26.0
UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized SliceView.
func (*SliceView[T, V])UnmarshalJSONFrom¶added inv1.88.0
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized SliceView.
typeStructView¶added inv1.26.0
type StructView[Tany] interface {// Valid reports whether the underlying Viewable is nil.Valid()bool// AsStruct returns a deep-copy of the underlying value.// It returns nil, if Valid() is false.AsStruct() T}
StructView represents the corresponding StructView of a Viewable. The concrete types aretypically generated by tailscale.com/cmd/viewer.
typeValuePointer¶added inv1.80.0
type ValuePointer[Tany] struct {// contains filtered or unexported fields}
ValuePointer provides a read-only view of a pointer to a value type,such as a primitive type or an immutable struct. Its Value and ValueOkmethods return a stack-allocated shallow copy of the underlying value.It is the caller's responsibility to ensure that Tis free from memory aliasing/mutation concerns.
funcValuePointerOf¶added inv1.80.0
func ValuePointerOf[Tany](v *T)ValuePointer[T]
ValuePointerOf returns an immutable view of a pointer to an immutable value.It is the caller's responsibility to ensure that Tis free from memory aliasing/mutation concerns.
func (ValuePointer[T])Clone¶added inv1.80.0
func (pValuePointer[T]) Clone() *T
Clone returns a shallow copy of the underlying value.
func (ValuePointer[T])Get¶added inv1.80.0
func (pValuePointer[T]) Get() T
Get returns a shallow copy of the value if the underlying pointer is non-nil.Otherwise, it returns a zero value.
func (ValuePointer[T])GetOk¶added inv1.80.0
func (pValuePointer[T]) GetOk() (value T, okbool)
GetOk returns a shallow copy of the underlying value and true if the underlyingpointer is non-nil. Otherwise, it returns a zero value and false.
func (ValuePointer[T])GetOr¶added inv1.80.0
func (pValuePointer[T]) GetOr(def T) T
GetOr returns a shallow copy of the underlying value if it is non-nil.Otherwise, it returns the provided default value.
func (ValuePointer[T])MarshalJSON¶added inv1.80.0
func (pValuePointer[T]) MarshalJSON() ([]byte,error)
MarshalJSON implementsjsonv1.Marshaler.
func (ValuePointer[T])MarshalJSONTo¶added inv1.88.0
func (pValuePointer[T]) MarshalJSONTo(enc *jsontext.Encoder)error
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (ValuePointer[T])String¶added inv1.80.0
func (pValuePointer[T]) String()string
String implementsfmt.Stringer.
func (*ValuePointer[T])UnmarshalJSON¶added inv1.80.0
func (p *ValuePointer[T]) UnmarshalJSON(b []byte)error
UnmarshalJSON implementsjsonv1.Unmarshaler.It must only be called on an uninitialized ValuePointer.
func (*ValuePointer[T])UnmarshalJSONFrom¶added inv1.88.0
func (p *ValuePointer[T]) UnmarshalJSONFrom(dec *jsontext.Decoder)error
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.It must only be called on an uninitialized ValuePointer.
func (ValuePointer[T])Valid¶added inv1.80.0
func (pValuePointer[T]) Valid()bool
Valid reports whether the underlying pointer is non-nil.
typeViewCloner¶added inv1.26.0
type ViewCloner[Tany, VStructView[T]] interface {// View returns a read-only view of Viewable.// If Viewable is nil, View().Valid() reports false.View() V// Clone returns a deep-clone of Viewable.// It returns nil, when Viewable is nil.Clone() T}
ViewCloner is any type that has had View and Clone funcs generated usingtailscale.com/cmd/viewer.