Skip to content

Commit be64d32

Browse files
committed
must
1 parent 0719030 commit be64d32

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

number_text.go

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func FloatToStringConverter[T Float](from T) (to string) {
1616
}
1717

1818
// StringToIntConverter parses int from string
19+
//
20+
// On error returns default value (0)
1921
func StringToIntConverter[T Int](from string) (to T) {
2022
n, err := strconv.Atoi(from)
2123
if err != nil {
@@ -24,7 +26,20 @@ func StringToIntConverter[T Int](from string) (to T) {
2426
return T(n)
2527
}
2628

29+
// MustStringToIntConverter parses int from string
30+
//
31+
// On error panics
32+
func MustStringToIntConverter[T Int](from string) (to T) {
33+
n, err := strconv.Atoi(from)
34+
if err != nil {
35+
panic(err)
36+
}
37+
return T(n)
38+
}
39+
2740
// StringToIntConverter parses float from string
41+
//
42+
// On error returns default value (0)
2843
func StringToFloatConverter[T Float](from string) (to T) {
2944
const bitSize = 64
3045
n, err := strconv.ParseFloat(from, bitSize)
@@ -33,3 +48,15 @@ func StringToFloatConverter[T Float](from string) (to T) {
3348
}
3449
return T(n)
3550
}
51+
52+
// MustStringToFloatConverter parses float from string
53+
//
54+
// On error panics
55+
func MustStringToFloatConverter[T Float](from string) (to T) {
56+
const bitSize = 64
57+
n, err := strconv.ParseFloat(from, bitSize)
58+
if err != nil {
59+
panic(err)
60+
}
61+
return T(n)
62+
}

0 commit comments

Comments
 (0)