skinsuit/equals

Search:
Group by:
Source   Edit  

generates == for objects including case objects

Example:

import skinsuit/equals
type Foo {.equals.} = object
  name: string
  case kind: bool
  of false:
    a: int
  of true:
    b: float

assert Foo(name: "abc", kind: false, a: 1) == Foo(name: "abc", kind: false, a: 1)
assert Foo(name: "abc", kind: false, a: 1) != Foo(name: "abc", kind: true, b: 1)
assert Foo(name: "abc", kind: false, a: 1) != Foo(name: "def", kind: false, a: 1)

Macros

macro equals(body)
generates `==` proc for object types, either as type pragma or statement,
i.e. ``type Foo {.equals.} = ...` or `equals Foo`
(or `equals *Foo` to export)

type pragma version will not work with recursive types,
write `equals Foo`/`equals *Foo` after type section
Source   Edit  
macro equalsForwardDecl(body)

generates forward declaration of equals, useful for mutually recursive types

used like equalsForwardDecl T or equalsForwardDecl *T (exported)

Source   Edit