stringconv

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package stringconv provides functions for string conversions to various number types. It simplifies the conversion (casting) between strings and various numeric types in Go, such as int, int64, uint, etc., in a secure manner that gracefully handles type overflows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToWholeNumber

func ToWholeNumber[T WholeNumber](str string) (T, error)

ToWholeNumber safely converts a string to a given whole number type (e.g., int, uint) with positive or negative handling. It returns the converted number and an error if the conversion fails.

Types

type WholeNumber

type WholeNumber interface {
	uint | uint8 | uint16 | uint32 | uint64 | int | int8 | int16 | int32 | int64
}

WholeNumber is a type constraint that includes all integer types.

Jump to

Keyboard shortcuts

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