-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add WrapUintEnum and WrapFloatEnum (#34)
- Loading branch information
1 parent
bbe7666
commit ec74283
Showing
10 changed files
with
149 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package enum | ||
|
||
import ( | ||
"database/sql/driver" | ||
"fmt" | ||
|
||
"github.com/xybor-x/enum/internal/core" | ||
) | ||
|
||
// WrapFloatEnum provides a set of built-in methods to simplify working with | ||
// float64 enums. | ||
type WrapFloatEnum[underlyingEnum any] float64 | ||
|
||
func (e WrapFloatEnum[underlyingEnum]) IsValid() bool { | ||
return IsValid(e) | ||
} | ||
|
||
func (e WrapFloatEnum[underlyingEnum]) MarshalJSON() ([]byte, error) { | ||
return MarshalJSON(e) | ||
} | ||
|
||
func (e *WrapFloatEnum[underlyingEnum]) UnmarshalJSON(data []byte) error { | ||
return UnmarshalJSON(data, e) | ||
} | ||
|
||
func (e WrapFloatEnum[underlyingEnum]) Value() (driver.Value, error) { | ||
return ValueSQL(e) | ||
} | ||
|
||
func (e *WrapFloatEnum[underlyingEnum]) Scan(a any) error { | ||
return ScanSQL(a, e) | ||
} | ||
|
||
func (e WrapFloatEnum[underlyingEnum]) String() string { | ||
return ToString(e) | ||
} | ||
|
||
func (e WrapFloatEnum[underlyingEnum]) GoString() string { | ||
if !e.IsValid() { | ||
return fmt.Sprintf("%f", e) | ||
} | ||
|
||
return fmt.Sprintf("%f (%s)", e, e) | ||
} | ||
|
||
// WARNING: Only use this function if you fully understand its behavior. | ||
// It might cause unexpected results if used improperly. | ||
func (e WrapFloatEnum[underlyingEnum]) newEnum(id int64, s string) any { | ||
return core.MapAny(id, WrapFloatEnum[underlyingEnum](id), s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package enum | ||
|
||
import ( | ||
"database/sql/driver" | ||
"fmt" | ||
|
||
"github.com/xybor-x/enum/internal/core" | ||
) | ||
|
||
// WrapUintEnum provides a set of built-in methods to simplify working with | ||
// uint64 enums. | ||
type WrapUintEnum[underlyingEnum any] uint64 | ||
|
||
func (e WrapUintEnum[underlyingEnum]) IsValid() bool { | ||
return IsValid(e) | ||
} | ||
|
||
func (e WrapUintEnum[underlyingEnum]) MarshalJSON() ([]byte, error) { | ||
return MarshalJSON(e) | ||
} | ||
|
||
func (e *WrapUintEnum[underlyingEnum]) UnmarshalJSON(data []byte) error { | ||
return UnmarshalJSON(data, e) | ||
} | ||
|
||
func (e WrapUintEnum[underlyingEnum]) Value() (driver.Value, error) { | ||
return ValueSQL(e) | ||
} | ||
|
||
func (e *WrapUintEnum[underlyingEnum]) Scan(a any) error { | ||
return ScanSQL(a, e) | ||
} | ||
|
||
func (e WrapUintEnum[underlyingEnum]) String() string { | ||
return ToString(e) | ||
} | ||
|
||
func (e WrapUintEnum[underlyingEnum]) GoString() string { | ||
if !e.IsValid() { | ||
return fmt.Sprintf("%d", e) | ||
} | ||
|
||
return fmt.Sprintf("%d (%s)", e, e) | ||
} | ||
|
||
// WARNING: Only use this function if you fully understand its behavior. | ||
// It might cause unexpected results if used improperly. | ||
func (e WrapUintEnum[underlyingEnum]) newEnum(id int64, s string) any { | ||
return core.MapAny(id, WrapUintEnum[underlyingEnum](id), s) | ||
} |