Skip to content

Commit

Permalink
fix safeConvert
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Sep 18, 2024
1 parent b37133c commit 2d9e57b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libp2p/utility.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ when defined(libp2p_agents_metrics):
KnownLibP2PAgents* {.strdefine.} = "nim-libp2p"
KnownLibP2PAgentsSeq* = KnownLibP2PAgents.safeToLowerAscii().tryGet().split(",")

template safeConvert*[T: SomeInteger, S: Ordinal](value: S): T =
proc safeConvert*[T: SomeInteger](value: SomeOrdinal): T =
type S = typeof(value)
## Converts `value` from S to `T` iff `value` is guaranteed to be preserved.
when int64(T.low) <= int64(S.low()) and uint64(T.high) >= uint64(S.high):
T(value)
Expand Down

0 comments on commit 2d9e57b

Please sign in to comment.