Documentation
¶
Overview ¶
github.com/hauntedness/std/hv is a fork of github.com/samber/mo/option.
Index ¶
- func Err(format string, args ...any) error
- func Errf(err error, format string, args ...any) error
- func Error(err error, message string) error
- func OrZero[T any](v *T) T
- func Ptr[T any](v T) *T
- func Zero[T any]() T
- type Frame
- type HvOption
- type Option
- func (o Option[T]) Get() (T, bool)
- func (o *Option[T]) GobDecode(data []byte) error
- func (o Option[T]) GobEncode() ([]byte, error)
- func (o Option[T]) IsAbsent() bool
- func (o Option[T]) IsPresent() bool
- func (o Option[T]) IsZero() bool
- func (o Option[T]) MarshalBinary() ([]byte, error)
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MarshalText() ([]byte, error)
- func (o Option[T]) MustGet() T
- func (o Option[T]) OrElse(fallback T) T
- func (o Option[T]) OrEmpty() T
- func (o *Option[T]) Scan(src any) error
- func (o Option[T]) ToPtr() *T
- func (o *Option[T]) UnmarshalBinary(data []byte) error
- func (o *Option[T]) UnmarshalJSON(b []byte) error
- func (o *Option[T]) UnmarshalText(data []byte) error
- func (o Option[T]) Value() (driver.Value, error)
- type StackTrace
- type TracedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Err ¶ added in v0.23.1
Err formats according to a format specifier and returns the string as a value that satisfies error. Err also records the stack trace at the point it was called.
func Errf ¶ added in v0.23.2
Errf wraps an error into a TracedError, appending a formatted message. If the error is already a TracedError, it appends the message to the existing one.
func Error ¶ added in v0.23.1
Error construct stack TracedError by err and message.
Types ¶
type Frame ¶ added in v0.23.1
type Frame uintptr
Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.
func (Frame) Format ¶ added in v0.23.1
Format formats the frame according to the fmt.Formatter interface.
%s source file %d source line %n function name %v equivalent to %s:%d
Format accepts flags that alter the printing of some verbs, as follows:
%+s function name and path of source file relative to the compile time
GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v equivalent to %+s:%d
func (Frame) MarshalText ¶ added in v0.23.1
MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.
type HvOption ¶ added in v0.20.0
type HvOption interface {
// contains filtered or unexported methods
}
HvOption is used to distinguish Option[T] with other types. you may need this in rare corner cases. e.g. when you want to test a reflect.Value is hv.Option. It is hard to instantiate all possible hv.Option[T].
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option is a container for an optional value of type T. If value exists, Option is of type Some. If the value is absent, Option is of type None.
func (Option[T]) MarshalBinary ¶
MarshalBinary is the interface implemented by an object that can marshal itself into a binary form.
func (Option[T]) MarshalJSON ¶
MarshalJSON encodes Option into json.
func (Option[T]) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Option[T]) OrElse ¶
func (o Option[T]) OrElse(fallback T) T
OrElse returns value if present or default value.
func (Option[T]) OrEmpty ¶
func (o Option[T]) OrEmpty() T
OrEmpty returns value if present or empty value.
func (Option[T]) ToPtr ¶ added in v0.18.2
func (o Option[T]) ToPtr() *T
ToPtr returns value if present or a nil pointer.
func (*Option[T]) UnmarshalBinary ¶
UnmarshalBinary is the interface implemented by an object that can unmarshal a binary representation of itself.
func (*Option[T]) UnmarshalJSON ¶
UnmarshalJSON decodes Option from json.
func (*Option[T]) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type StackTrace ¶ added in v0.23.1
type StackTrace []Frame
StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
func (StackTrace) Format ¶ added in v0.23.1
func (st StackTrace) Format(s fmt.State, verb rune)
Format formats the stack of Frames according to the fmt.Formatter interface.
%s lists source files for each Frame in the stack %v lists the source file and line number for each Frame in the stack
Format accepts flags that alter the printing of some verbs, as follows:
%+v Prints filename, function, and line number for each Frame in the stack.
type TracedError ¶ added in v0.23.10
type TracedError struct {
// contains filtered or unexported fields
}
func (*TracedError) Error ¶ added in v0.23.10
func (w *TracedError) Error() string
func (*TracedError) Message ¶ added in v0.23.10
func (w *TracedError) Message() string
func (*TracedError) SetUnderlying ¶ added in v0.24.0
func (w *TracedError) SetUnderlying(err error)
SetUnderlying replace the underlying to new one.
func (*TracedError) Stack ¶ added in v0.23.10
func (w *TracedError) Stack() StackTrace
func (TracedError) StackTrace ¶ added in v0.23.10
func (s TracedError) StackTrace() StackTrace
func (*TracedError) Unwrap ¶ added in v0.23.10
func (w *TracedError) Unwrap() error
Unwrap provides compatibility for Go 1.13 error chains.