Utilities related to import and symbol resolution.
Experimental API, subject to change.
proc privateAccess(t: typedesc) {.magic: "PrivateAccess", ...raises: [], tags: [],
forbids: [].}t in current scope. Example: cmd: -d:nimImportutilsExample
# here we're importing a module containing:
# type
# Foo = object
# f0: int # private
# Goo*[T] = object
# g0: int # private
# proc initFoo*(): auto = Foo()
var f = initFoo()
block:
assert not compiles(f.f0)
privateAccess(f.type)
f.f0 = 1 # accessible in this scope
block:
assert f.f0 == 1 # still in scope
assert not compiles(f.f0)
# this also works with generics
privateAccess(Goo)
assert Goo[float](g0: 1).g0 == 1 Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/importutils.html