Why generic convertor doesn't work?
Nim
import strutils
type Direction = enum top, right, bottom, left
converter to_enum[T: enum]*(s: string): T = parse_enum[T](s)
# converter to_enum*(s: string): Direction = parse_enum[Direction](s)
let d: Direction = "top"
echo d
Error:
Error: converter needs a return type
import strutils
type Direction = enum top, right, bottom, left
proc to_enum[T: enum](s: string): T = parse_enum[T](s)
# Compile Error: cannot instantiate: 'T'
# let d: Direction = to_enum("top")
let d: Direction = to_enum[Direction]("top")
echo d
Generic converter like this work:
import strutils
type
StringT[T] = string
type Direction = enum top, right, bottom, left
converter to_enum*[T: enum](s: StringT[T]): T = parse_enum[T](s)
let d: Direction = StringT[Direction]("top")
echo d
By the way, export marker * must be placed right after an identifier like to_enum*[T], not like to_enum[T]*.