Note also that procedures are a pointer type under the hood, so you don't 
really need Option:
    
    
    import std/options
    
    type
      Callback = proc(name: string, length: int) {.nimcall.}
      
      TestOptions = object
        name: string
        length: int
        callback: Callback
    
    proc show(name: string, length: int) =
      echo "Callback executed: ", name, " is ", length, " inches long"
    
    let
      option1 = TestOptions(name: "foot", length: 12)
      option2 = TestOptions(name: "inch", length:  1)
      option3 = TestOptions(name: "yard", length:  36, callback: show)
    
    proc test(options: TestOptions) =
      echo "Options = ", options
      
      if not options.callback.isNil:
        options.callback(options.name, options.length)
      else:
        echo "No callback supplied"
    
    test option1
    test option2
    test option3
    
    
    Run

The options module knows this, and basically just turns into a null-check in 
this scenario, so it's just a matter of ergonomics and preference which one you 
use.

Reply via email to