libp2p/utility

    Dark Mode
Search:
Group by:
  Source   Edit

Procs

proc capLen[T](s: var seq[T]; length: Natural) {....raises: [].}
  Source   Edit
func shortLog(item: openArray[byte]): string {....raises: [], tags: [].}
  Source   Edit
func shortLog(item: string): string {....raises: [], tags: [].}
  Source   Edit

Macros

macro withValue[T](self: Opt[T] | Option[T]; value, body, elseStmt: untyped): untyped {.
    ...raises: [].}
  Source   Edit

Templates

template compilesOr(a, b: untyped): untyped
  Source   Edit
template exceptionToAssert(body: untyped): untyped
  Source   Edit
template exclIfIt[T](set: var HashSet[T]; condition: untyped)
  Source   Edit
template public() {.pragma.}
  Source   Edit
template safeConvert[T: SomeInteger; S: Ordinal](value: S): T
Converts value from S to T iff value is guaranteed to be preserved.   Source   Edit
template toOpt[T, E](self: Result[T, E]): Opt[T]
  Source   Edit
template valueOr[T](self: Option[T]; body: untyped): untyped
  Source   Edit
template withValue[T](self: Opt[T] | Option[T]; value, body: untyped): untyped

This template provides a convenient way to work with Option types in Nim. It allows you to execute a block of code (body) only when the Option is not empty.

self is the Option instance being checked. value is the variable name to be used within the body for the unwrapped value. body is a block of code that is executed only if self contains a value.

The value within body is automatically unwrapped from the Option, making it simpler to work with without needing explicit checks or unwrapping.

Example:

let myOpt = Opt.some(5)
myOpt.withValue(value):
  echo value # Will print 5

Note: This is a template, and it will be inlined at the call site, offering good performance.

  Source   Edit