Documentation ¶
Overview ¶
Package views provides read-only accessors for commonly used value types.
Index ¶
- func SliceContains[T comparable](v Slice[T], e T) bool
- type IPPrefixSlice
- func (v IPPrefixSlice) AppendTo(dst []netip.Prefix) []netip.Prefix
- func (v IPPrefixSlice) AsSlice() []netip.Prefix
- func (v IPPrefixSlice) At(i int) netip.Prefix
- func (v IPPrefixSlice) ContainsExitRoutes() bool
- func (v IPPrefixSlice) ContainsFunc(f func(netip.Prefix) bool) bool
- func (v IPPrefixSlice) ContainsIP(ip netip.Addr) bool
- func (v IPPrefixSlice) ContainsNonExitSubnetRoutes() bool
- func (v IPPrefixSlice) Filter(f func(netip.Prefix) bool) []netip.Prefix
- func (v IPPrefixSlice) IsNil() bool
- func (v IPPrefixSlice) Len() int
- func (v IPPrefixSlice) MarshalJSON() ([]byte, error)
- func (v *IPPrefixSlice) UnmarshalJSON(b []byte) error
- func (v IPPrefixSlice) Unwrap() Slice[netip.Prefix]
- type Map
- type MapFn
- type MapRangeFn
- type Slice
- 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]) MarshalJSON() ([]byte, error)
- func (v *Slice[T]) UnmarshalJSON(b []byte) error
- type SliceView
- 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]) MarshalJSON() ([]byte, error)
- func (v *SliceView[T, V]) UnmarshalJSON(b []byte) error
- type StructView
- type ViewCloner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SliceContains ¶
func SliceContains[T comparable](v Slice[T], e T) bool
SliceContains reports whether v contains element e.
As it runs in O(n) time, use with care.
Types ¶
type IPPrefixSlice ¶
type IPPrefixSlice struct {
// contains filtered or unexported fields
}
IPPrefixSlice is a read-only accessor for a slice of netip.Prefix.
func IPPrefixSliceOf ¶
func IPPrefixSliceOf(x []netip.Prefix) IPPrefixSlice
IPPrefixSliceOf returns a IPPrefixSlice for the provided slice.
func (IPPrefixSlice) AppendTo ¶
func (v IPPrefixSlice) AppendTo(dst []netip.Prefix) []netip.Prefix
AppendTo appends the underlying slice values to dst.
func (IPPrefixSlice) AsSlice ¶
func (v IPPrefixSlice) AsSlice() []netip.Prefix
AsSlice returns a copy of underlying slice.
func (IPPrefixSlice) At ¶
func (v IPPrefixSlice) At(i int) netip.Prefix
At returns the IPPrefix at index `i` of the slice.
func (IPPrefixSlice) ContainsExitRoutes ¶
func (v IPPrefixSlice) ContainsExitRoutes() bool
ContainsExitRoutes reports whether v contains ExitNode Routes.
func (IPPrefixSlice) ContainsFunc ¶
func (v IPPrefixSlice) ContainsFunc(f func(netip.Prefix) bool) bool
PrefixesContainsFunc reports whether f is true for any IPPrefix in the slice.
func (IPPrefixSlice) ContainsIP ¶
func (v IPPrefixSlice) ContainsIP(ip netip.Addr) bool
PrefixesContainsIP reports whether any IPPrefix contains IP.
func (IPPrefixSlice) ContainsNonExitSubnetRoutes ¶
func (v IPPrefixSlice) ContainsNonExitSubnetRoutes() bool
ContainsNonExitSubnetRoutes reports whether v contains Subnet Routes other than ExitNode Routes.
func (IPPrefixSlice) IsNil ¶
func (v IPPrefixSlice) IsNil() bool
IsNil reports whether the underlying slice is nil.
func (IPPrefixSlice) MarshalJSON ¶
func (v IPPrefixSlice) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*IPPrefixSlice) UnmarshalJSON ¶
func (v *IPPrefixSlice) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a view over a map whose values are immutable.
func MapOf ¶
func MapOf[K comparable, V comparable](m map[K]V) Map[K, V]
MapOf returns a view over m. It is the caller's responsibility to make sure K and V is immutable, if this is being used to provide a read-only view over m.
func (Map[K, V]) GetOk ¶
GetOk returns the element with key k and a bool representing whether the key is in map.
func (Map[K, V]) Range ¶
func (m Map[K, V]) Range(f MapRangeFn[K, V])
Range calls f for every k,v pair in the underlying map. It stops iteration immediately if f returns false.
type MapFn ¶
type MapFn[K comparable, T any, V any] 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.
func MapFnOf ¶
func MapFnOf[K comparable, T any, V any](m map[K]T, f func(T) V) MapFn[K, T, V]
MapFnOf returns a MapFn for m.
func (MapFn[K, T, V]) GetOk ¶
GetOk returns the element with key k and a bool representing whether the key is in map.
func (MapFn[K, T, V]) Range ¶
func (m MapFn[K, T, V]) Range(f MapRangeFn[K, V])
Range calls f for every k,v pair in the underlying map. It stops iteration immediately if f returns false.
type MapRangeFn ¶
type MapRangeFn[K comparable, V any] func(k K, v V) (cont bool)
MapRangeFn is the func called from a Map.Range call. Implementations should return false to stop range.
type Slice ¶
type Slice[T any] struct { // contains filtered or unexported fields }
Slice is a read-only accessor for a slice.
func SliceOf ¶
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 ¶
func (v Slice[T]) AppendTo(dst []T) []T
AppendTo appends the underlying slice values to dst.
func (Slice[T]) AsSlice ¶
func (v Slice[T]) AsSlice() []T
AsSlice returns a copy of underlying slice.
func (Slice[T]) ContainsFunc ¶
ContainsFunc reports whether any element in v satisfies f(e).
As it runs in O(n) time, use with care.
func (Slice[T]) IndexFunc ¶
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]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Slice[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type SliceView ¶
type SliceView[T ViewCloner[T, V], V StructView[T]] struct { // contains filtered or unexported fields }
SliceView is a read-only wrapper around a struct which should only be exposed as a View.
func SliceOfViews ¶
func SliceOfViews[T ViewCloner[T, V], V StructView[T]](x []T) SliceView[T, V]
SliceOfViews returns a ViewSlice for x.
func (SliceView[T, V]) AppendTo ¶
func (v SliceView[T, V]) AppendTo(dst []V) []V
AppendTo appends the underlying slice values to dst.
func (SliceView[T, V]) AsSlice ¶
func (v SliceView[T, V]) AsSlice() []V
AsSlice returns a copy of underlying slice.
func (SliceView[T, V]) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*SliceView[T, V]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type StructView ¶
type StructView[T any] 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 are typically generated by tailscale.com/cmd/viewer.
type ViewCloner ¶
type ViewCloner[T any, V StructView[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 using tailscale.com/cmd/viewer.