No description
Find a file
2025-03-15 09:37:39 +01:00
src chore: improved proc docs 2025-03-15 09:37:39 +01:00
assert.nimble feat: DbC contracts 2025-03-13 14:29:06 +01:00
LICENCE feat: DbC contracts 2025-03-13 14:29:06 +01:00
README.md feat: DbC contracts 2025-03-13 14:29:06 +01:00

Design by Contract for Nim

A lightweight Design by Contract implementation for Nim allowing you to enforce preconditions and postconditions

Installation

nimble install assert

Usage

import assert
import math

proc divide(a, b: int): int {.contract.} =
  ## Integer division of a by b.
  ## Requires:
  ##   b != 0
  ## Ensures:
  ##   result * b == a
  result = a div b

Compile Options

  • Regular Build: Contracts fully enabled

    nim c program.nim
    
  • Production Build: No contract checks (zero overhead)

    nim c -d:noContracts program.nim
    

Note

When a contract is violated, the program terminates with an error message