Export statement

An export statement can be used for symbol forwarding so that client modules don’t need to import a module’s dependencies:

  1. # module B
  2. type MyObject* = object
  1. # module A
  2. import B
  3. export B.MyObject
  4. proc `$`*(x: MyObject): string = "my object"
  1. # module C
  2. import A
  3. # B.MyObject has been imported implicitly here:
  4. var x: MyObject
  5. echo $x

When the exported symbol is another module, all of its definitions will be forwarded. One can use an except list to exclude some of the symbols.

Notice that when exporting, one needs to specify only the module name:

  1. import foo/bar/baz
  2. export baz