mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-31 21:16:09 +00:00
e5df8c50d3
* style: nph setup * chore: formates codex/ and tests/ folder with nph 0.6.1
36 lines
1.0 KiB
Nim
36 lines
1.0 KiB
Nim
import std/strformat
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
type
|
|
ValidationGroups* = range[2 .. 65535]
|
|
MaxSlots* = int
|
|
ValidationConfig* = object
|
|
maxSlots: MaxSlots
|
|
groups: ?ValidationGroups
|
|
groupIndex: uint16
|
|
|
|
func init*(
|
|
_: type ValidationConfig,
|
|
maxSlots: MaxSlots,
|
|
groups: ?ValidationGroups,
|
|
groupIndex: uint16 = 0,
|
|
): ?!ValidationConfig =
|
|
if maxSlots < 0:
|
|
return failure "The value of maxSlots must be greater than " &
|
|
fmt"or equal to 0! (got: {maxSlots})"
|
|
if validationGroups =? groups and groupIndex >= uint16(validationGroups):
|
|
return failure "The value of the group index must be less than " &
|
|
fmt"validation groups! (got: {groupIndex = }, " & fmt"groups = {validationGroups})"
|
|
|
|
success ValidationConfig(maxSlots: maxSlots, groups: groups, groupIndex: groupIndex)
|
|
|
|
func maxSlots*(config: ValidationConfig): MaxSlots =
|
|
config.maxSlots
|
|
|
|
func groups*(config: ValidationConfig): ?ValidationGroups =
|
|
config.groups
|
|
|
|
func groupIndex*(config: ValidationConfig): uint16 =
|
|
config.groupIndex
|