-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenums_int.go
More file actions
43 lines (40 loc) · 1.24 KB
/
genums_int.go
File metadata and controls
43 lines (40 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package genums
// EnumInt is a specialized enum interface for integer-based enumerations.
// It extends BaseEnum with int as the underlying value type, providing
// type-safe integer enum functionality.
//
// Type parameters:
// - T: The concrete enum type that implements this interface
type EnumInt[T any] interface {
BaseEnum[T, int]
}
// enumIntImpl is the internal implementation of the EnumInt interface.
// It embeds enumImpl with int as the value type to provide all
// integer-specific enum functionality.
//
// Type parameters:
// - T: The concrete enum type (used for type safety)
type enumIntImpl[T any] struct {
enumImpl[T, int]
}
// NewEnumInt creates a new integer-based enum instance with the given value.
// This is the primary constructor for creating integer enum values.
//
// Type parameters:
// - T: The target enum type to create
//
// Parameters:
// - value: The integer value to wrap in the enum
//
// Returns:
// - A new EnumInt instance containing the specified value
//
// Example:
//
// type Priority EnumInt[Priority]
// high := NewEnumInt[Priority](1)
// medium := NewEnumInt[Priority](2)
// low := NewEnumInt[Priority](3)
func NewEnumInt[T any](value int) EnumInt[T] {
return enumIntImpl[T]{enumImpl[T, int]{value: value}}
}