Skip to content

what if I don't want the default behaviour of enum ? #77

@hamidb80

Description

@hamidb80

Hey,

I just want to store enums as ints,

wrapper.nim:

import jsony
import inner

type
    Enum = enum
        e1
        e2

echo fromJson("0", Enum)

inner.nim

import std/[parseutils]

proc parseHook*[T: enum](s: string, i: var int, v: var T) =
  var temp: int
  inc i, parseInt(s, temp, i)
  v = T temp

proc dumpHook*(s: var string, v: enum) =
  s.add $v.int

Expected behaviour

compiles successfully and considers enums as ints

Current output

/wrapper.nim(10, 14) template/generic instantiation of `fromJson` from here
/.nimble/jsony/jsony.nim(590, 4) 

Error: ambiguous call; both 

jsony.parseHook(s: string, i: var int, v: var T: enum) [proc declared in /.nimble/jsony/jsony.nim(406, 6)] 
and 
inner.parseHook(s: string, i: var int, v: var T: enum) [proc declared in inner.nim(3, 6)] 

match for: (string, int, Enum)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions