gost

package module
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 7 Imported by: 1

README

rusty

This is an attempt to bring some of the useful features of rust to the go language.

Documentation

Index

Constants

View Source
const (
	ErrXSeparator        = ";;"
	ErrXMessageSeparator = " : "
)
View Source
const (
	IsOk  switchOption = true
	IsErr switchOption = false
)

Variables

View Source
var (
	ErrMutexIsLocked = NewErrX(0, "mutex is locked")
)

Functions

func CloneArray

func CloneArray[S ~[]E, E any](s S) S

func SafeDeref

func SafeDeref[T any](t *T) T

func WithContext

func WithContext(ctx context.Context, fn func() error, onStop ...func()) (err error)

func WithContextPool

func WithContextPool(ctx context.Context, fn func() error, pool chan struct{}, onStop ...func()) (err error)

Types

type Arc

type Arc[V *X, X any] struct {
	// contains filtered or unexported fields
}

func NewArc

func NewArc[V *X, X any](v V) Arc[V, X]

func (Arc[V, X]) Read

func (a Arc[V, X]) Read() X

func (Arc[V, X]) Ref

func (a Arc[V, X]) Ref() V

type Enum

type Enum[V any] Variant[V]

func (Enum[V]) Enum

func (e Enum[V]) Enum() V

func (Enum[V]) New

func (e Enum[V]) New(Value V) Enum[V]

type ErrX added in v0.0.23

type ErrX struct {
	// contains filtered or unexported fields
}

func NewErrX added in v0.0.23

func NewErrX(code int, message ...string) *ErrX

func (*ErrX) AsMessage added in v0.0.24

func (x *ErrX) AsMessage(err error) *ErrX

func (*ErrX) BaseCode added in v0.0.23

func (x *ErrX) BaseCode() int

func (*ErrX) CmpBase added in v0.0.23

func (x *ErrX) CmpBase(code int) bool

func (*ErrX) CmpExt added in v0.0.23

func (x *ErrX) CmpExt(code int) bool

func (*ErrX) Error added in v0.0.23

func (x *ErrX) Error() string

Error Example: fmt.Println(newErr(_notFound, "not found").Extend(_order).Extend(134, "test").Error()) OUT: 404: "not found";; 1000: ;; 134: "test"

func (ErrX) ExtCode added in v0.0.26

func (x ErrX) ExtCode() int

func (*ErrX) Extend added in v0.0.23

func (x *ErrX) Extend(extCode int, messages ...string) *ErrX

func (*ErrX) ExtendMsg added in v0.0.23

func (x *ErrX) ExtendMsg(message string, messages ...string) *ErrX

func (*ErrX) HasExt added in v0.0.26

func (x *ErrX) HasExt(code int) bool

func (*ErrX) Is added in v0.0.25

func (x *ErrX) Is(target error) bool

func (*ErrX) IsX added in v0.0.26

func (x *ErrX) IsX(targetX *ErrX) bool

func (*ErrX) MarshalJSON added in v0.0.23

func (x *ErrX) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. Example:

{
	"code": 12,
	"message": "Order",
	"parent": [
		{
			"code": 1,
			"message": "Not found",
		}
	],
}

func (ErrX) Message added in v0.0.26

func (x ErrX) Message() string

type Error

type Error struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(baseCode int, extendedCode int, message string) *Error

func NewErrorUnknown added in v0.0.6

func NewErrorUnknown(message string) *Error

func (*Error) BaseCode

func (e *Error) BaseCode() int

func (*Error) Error

func (e *Error) Error() string

func (*Error) ExtendedCode

func (e *Error) ExtendedCode() int

func (*Error) IfErr added in v0.0.16

func (e *Error) IfErr(fn func(err *Error) *Error) *Error

func (*Error) IfNotErr added in v0.0.16

func (e *Error) IfNotErr(fn func() *Error) *Error

func (*Error) IntoStd added in v0.0.17

func (e *Error) IntoStd() error

func (*Error) Is added in v0.0.23

func (e *Error) Is(target *Error) bool

func (*Error) Join added in v0.0.23

func (e *Error) Join(err *Error) *Error

func (*Error) Joined added in v0.0.23

func (e *Error) Joined() []*Error

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

func (*Error) Message

func (e *Error) Message() string

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(data []byte) error

func (*Error) Unwrap added in v0.0.23

func (e *Error) Unwrap() []*Error

func (*Error) Wrap added in v0.0.23

func (e *Error) Wrap(message string) *Error

func (*Error) Wrapf added in v0.0.23

func (e *Error) Wrapf(template string, args ...any) *Error

type Mutex

type Mutex[V any] struct {
	// contains filtered or unexported fields
}

func NewMutex

func NewMutex[V any](v V) Mutex[V]

func (*Mutex[V]) Borrow

func (m *Mutex[V]) Borrow() Arc[*V, V]

func (*Mutex[V]) BorrowMut

func (m *Mutex[V]) BorrowMut() *V

func (*Mutex[V]) Release

func (m *Mutex[V]) Release()

func (*Mutex[V]) Return

func (m *Mutex[V]) Return(v V)

func (*Mutex[V]) SetWithLock added in v0.0.4

func (m *Mutex[V]) SetWithLock(v V)

func (*Mutex[V]) TryBorrow

func (m *Mutex[V]) TryBorrow() Result[V]

func (*Mutex[V]) UnsafeCopy added in v0.0.27

func (m *Mutex[V]) UnsafeCopy() V

UnsafeCopy is safe with primitive types. Type shouldn't contain interface in fields or definition.

func (*Mutex[V]) UpdateWithLock added in v0.0.4

func (m *Mutex[V]) UpdateWithLock(fn func(v *V))

func (*Mutex[V]) WithLock added in v0.0.27

func (m *Mutex[V]) WithLock(fn func(v V) V)

type MutexSlice added in v0.0.28

type MutexSlice[V any] struct {
	// contains filtered or unexported fields
}

func NewMutexSlice added in v0.0.28

func NewMutexSlice[V any](s []V) *MutexSlice[V]

func (*MutexSlice[V]) Clear added in v0.0.28

func (s *MutexSlice[V]) Clear()

func (*MutexSlice[V]) ClearRange added in v0.0.30

func (s *MutexSlice[V]) ClearRange(i, j int)

func (*MutexSlice[V]) Done added in v0.0.31

func (s *MutexSlice[V]) Done() []V

Done finishes the usage of the mutex and returns the slice.

func (*MutexSlice[V]) Get added in v0.0.28

func (s *MutexSlice[V]) Get(i int) V

func (*MutexSlice[V]) GetRange added in v0.0.30

func (s *MutexSlice[V]) GetRange(i, j int) []V

func (*MutexSlice[V]) InsertAt added in v0.0.28

func (s *MutexSlice[V]) InsertAt(i int, v V) *MutexSlice[V]

func (*MutexSlice[V]) LPop added in v0.0.28

func (s *MutexSlice[V]) LPop() V

func (*MutexSlice[V]) LPush added in v0.0.28

func (s *MutexSlice[V]) LPush(v V) int

func (*MutexSlice[V]) Len added in v0.0.28

func (s *MutexSlice[V]) Len() int

func (*MutexSlice[V]) RPop added in v0.0.28

func (s *MutexSlice[V]) RPop() V

func (*MutexSlice[V]) RPush added in v0.0.28

func (s *MutexSlice[V]) RPush(v V) int

func (*MutexSlice[V]) RemoveAt added in v0.0.28

func (s *MutexSlice[V]) RemoveAt(i int) V

func (*MutexSlice[V]) Set added in v0.0.28

func (s *MutexSlice[V]) Set(i int, v V)

func (*MutexSlice[V]) SetRange added in v0.0.30

func (s *MutexSlice[V]) SetRange(i, j int, v []V)

func (*MutexSlice[V]) UnsafeCopy added in v0.0.30

func (s *MutexSlice[V]) UnsafeCopy() []V

UnsafeCopy might be unsafe if array contains pointers or interfaces.

func (*MutexSlice[V]) UnsafeSlice added in v0.0.31

func (s *MutexSlice[V]) UnsafeSlice() []V

UnsafeSlice might be unsafe if you attempt to modify the MutexSlice after the call.

type Nothing

type Nothing struct{}

type Option

type Option[V any] struct {
	// contains filtered or unexported fields
}

func None

func None[V any]() Option[V]

func Some

func Some[V any](value V) Option[V]

func (Option[V]) IsNone

func (o Option[V]) IsNone() bool

func (Option[V]) IsSome

func (o Option[V]) IsSome() bool

func (Option[V]) None

func (Option[V]) None() Option[V]

func (Option[V]) Some

func (Option[V]) Some(value V) Option[V]

func (Option[V]) Unwrap

func (o Option[V]) Unwrap() V

func (Option[V]) UnwrapOrDefault

func (o Option[V]) UnwrapOrDefault() V

func (Option[V]) UnwrapOrElse

func (o Option[V]) UnwrapOrElse(fn func() V) V

type Pair

type Pair[L any, R any] struct {
	Left  L
	Right R
}

func NewPair added in v0.0.29

func NewPair[L any, R any](l L, r R) Pair[L, R]

type Result

type Result[V any] struct {
	// contains filtered or unexported fields
}

func Err

func Err[V any](err *ErrX) Result[V]

func Ok

func Ok[V any](value V) Result[V]

func (Result[V]) Err

func (Result[V]) Err(err *ErrX) Result[V]

func (Result[V]) ErrNew added in v0.0.6

func (Result[V]) ErrNew(code, extCode int, msg ...string) Result[V]

func (Result[V]) ErrNewUnknown added in v0.0.6

func (Result[V]) ErrNewUnknown(msg string) Result[V]

func (Result[V]) Error

func (r Result[V]) Error() *ErrX

func (Result[V]) ErrorStd added in v0.0.18

func (r Result[V]) ErrorStd() error

func (*Result[V]) Expect

func (r *Result[V]) Expect(msg string) V

func (Result[V]) IsErr

func (r Result[V]) IsErr() bool

func (Result[V]) IsOk

func (r Result[V]) IsOk() bool

func (Result[V]) Ok

func (Result[V]) Ok(value V) Result[V]

func (Result[V]) Switch added in v0.0.3

func (r Result[V]) Switch() switchOption

func (Result[V]) Unwrap

func (r Result[V]) Unwrap() V

func (Result[V]) UnwrapOr added in v0.0.7

func (r Result[V]) UnwrapOr(v V) V

func (Result[V]) UnwrapOrDefault

func (r Result[V]) UnwrapOrDefault() (v V)

func (Result[V]) UnwrapOrElse

func (r Result[V]) UnwrapOrElse(fn func(err *ErrX) V) V

type ResultN added in v0.0.7

type ResultN struct {
	// contains filtered or unexported fields
}

func ErrN added in v0.0.7

func ErrN(err *ErrX) ResultN

func (ResultN) Err added in v0.0.7

func (ResultN) Err(err *ErrX) ResultN

func (ResultN) ErrNew added in v0.0.7

func (ResultN) ErrNew(code, extCode int, msg ...string) ResultN

func (ResultN) ErrNewUnknown added in v0.0.7

func (ResultN) ErrNewUnknown(msg string) ResultN

func (ResultN) Error added in v0.0.7

func (r ResultN) Error() *ErrX

func (ResultN) ErrorStd added in v0.0.18

func (r ResultN) ErrorStd() error

func (ResultN) IsErr added in v0.0.7

func (r ResultN) IsErr() bool

func (ResultN) IsOk added in v0.0.7

func (r ResultN) IsOk() bool

func (ResultN) Ok added in v0.0.7

func (ResultN) Ok() ResultN

func (ResultN) Switch added in v0.0.7

func (r ResultN) Switch() switchOption

func (ResultN) Unwrap added in v0.0.35

func (r ResultN) Unwrap()

type RwLock

type RwLock[V any] struct {
	// contains filtered or unexported fields
}

func NewRwLock

func NewRwLock[V any](v V) RwLock[V]

func (*RwLock[V]) RBorrow

func (m *RwLock[V]) RBorrow() Arc[*V, V]

func (*RwLock[V]) RTryBorrow

func (m *RwLock[V]) RTryBorrow() Result[V]

func (*RwLock[V]) ReadAndRelease added in v0.0.22

func (m *RwLock[V]) ReadAndRelease() V

func (*RwLock[V]) Release

func (m *RwLock[V]) Release()

func (*RwLock[V]) SetWithLock added in v0.0.11

func (m *RwLock[V]) SetWithLock(v V)

func (*RwLock[V]) WBorrow

func (m *RwLock[V]) WBorrow() Arc[*V, V]

func (*RwLock[V]) WRelease added in v0.0.8

func (m *RwLock[V]) WRelease()

func (*RwLock[V]) WReturn

func (m *RwLock[V]) WReturn(v V)

func (*RwLock[V]) WTryBorrow

func (m *RwLock[V]) WTryBorrow() Result[V]

func (*RwLock[V]) WithLock added in v0.0.12

func (m *RwLock[V]) WithLock(fn func(v V) V)

type Scoped

type Scoped interface {
	Lock() func()
}

func NewDebugScopedLock

func NewDebugScopedLock(log ...func()) Scoped

func NewScopedLock

func NewScopedLock() Scoped

type SecureMutexLocked added in v0.0.3

type SecureMutexLocked[V any] struct {
	// contains filtered or unexported fields
}

func (SecureMutexLocked[V]) Unlock added in v0.0.3

func (m SecureMutexLocked[V]) Unlock() SecureMutexUnlocked[V]

type SecureMutexUnlocked added in v0.0.3

type SecureMutexUnlocked[V any] struct {
	// contains filtered or unexported fields
}

func NewSecureMutex added in v0.0.3

func NewSecureMutex[V any]() SecureMutexUnlocked[V]

func NewSecureMutexV added in v0.0.22

func NewSecureMutexV[V any](v V) SecureMutexUnlocked[V]

func (SecureMutexUnlocked[V]) Lock added in v0.0.3

func (m SecureMutexUnlocked[V]) Lock() SecureMutexLocked[V]

func (SecureMutexUnlocked[V]) Set added in v0.0.22

func (m SecureMutexUnlocked[V]) Set(v V) SecureMutexUnlocked[V]

func (SecureMutexUnlocked[V]) Value added in v0.0.22

func (m SecureMutexUnlocked[V]) Value() Arc[*V, V]

type Tuple

type Tuple[V any] []V

type Variant

type Variant[V any] struct {
	Value V
}

func NewVariant

func NewVariant[V any](Value V) Variant[V]

func (Variant[V]) Enum

func (v Variant[V]) Enum() V

func (Variant[V]) New

func (v Variant[V]) New(Value V) Enum[V]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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