From 1309c6deeef833649e14edd2b962fe16eaef7a38 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 5 Nov 2025 14:16:57 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20constrai?= =?UTF-8?q?nts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constraints/constraints.go | 54 ++++++++++++++++++++++++++++++++++++++ micro/microfunctions.go | 5 ++-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 constraints/constraints.go diff --git a/constraints/constraints.go b/constraints/constraints.go new file mode 100644 index 00000000..9d260bab --- /dev/null +++ b/constraints/constraints.go @@ -0,0 +1,54 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package constraints defines a set of useful constraints to be used +// with type parameters. +package constraints + +import "cmp" + +// Signed is a constraint that permits any signed integer type. +// If future releases of Go add new predeclared signed integer types, +// this constraint will be modified to include them. +type Signed interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 +} + +// Unsigned is a constraint that permits any unsigned integer type. +// If future releases of Go add new predeclared unsigned integer types, +// this constraint will be modified to include them. +type Unsigned interface { + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr +} + +// Integer is a constraint that permits any integer type. +// If future releases of Go add new predeclared integer types, +// this constraint will be modified to include them. +type Integer interface { + Signed | Unsigned +} + +// Float is a constraint that permits any floating-point type. +// If future releases of Go add new predeclared floating-point types, +// this constraint will be modified to include them. +type Float interface { + ~float32 | ~float64 +} + +// Complex is a constraint that permits any complex numeric type. +// If future releases of Go add new predeclared complex numeric types, +// this constraint will be modified to include them. +type Complex interface { + ~complex64 | ~complex128 +} + +// Ordered is a constraint that permits any ordered type: any type +// that supports the operators < <= >= >. +// If future releases of Go add new ordered types, +// this constraint will be modified to include them. +// +// This type is redundant since Go 1.21 introduced [cmp.Ordered]. +// +//go:fix inline +type Ordered = cmp.Ordered diff --git a/micro/microfunctions.go b/micro/microfunctions.go index 97516bf6..703f4c65 100644 --- a/micro/microfunctions.go +++ b/micro/microfunctions.go @@ -1,3 +1,4 @@ +// копия "golang.org/x/exp/constraints" // модуль с вспомогательными небольшими функциями package micro @@ -10,9 +11,9 @@ import ( "errors" "fmt" "github.com/ManyakRus/starter/constants_starter" + "github.com/ManyakRus/starter/constraints" "github.com/dromara/carbon/v2" "github.com/google/uuid" - "golang.org/x/exp/constraints" "google.golang.org/protobuf/types/known/timestamppb" "hash/fnv" "math" @@ -805,7 +806,7 @@ func SaveTempFile_err(bytes []byte) (string, error) { // Hash - возвращает число хэш из строки func Hash(s string) uint32 { h := fnv.New32a() - h.Write([]byte(s)) + _, _ = h.Write([]byte(s)) return h.Sum32() }