# In reply to @mratsim "https://github.com/nim-lang/Nim/issues/7632": This ended # up being the solution: # <../util.nim> import std/tables const TYPE_COLORS = {"type1": "red", ...}.to_table() proc date_formatter(in_stamp: string): string = ... # import std/tables import std/strformat import ../util proc generic_metadata_printer( struct: MetadataType1 | MetadataType2 ): string = # Both `MetadataType1` and `MetadataType2` have the fields `event_stamp` and `mdtype` block: let dformat {.inject.} = date_formatter result &= &"Let's format a datestamp: {dformat(struct.event_stamp)}\n" block: proc `[]`[K, V](t: Table[K, V], key: K): V {.inject.} = return t.getOrDefault(key) result &= &"Let's also pick a color: {TYPE_COLORS[struct.mdtype]}\n" ...