#macro argument type [solved]

2 messages ยท Page 1 of 1 (latest)

topaz heart
#

hey ๐Ÿ‘‹

I'm trying to implement a macro by having troubles doing so, here's an example of what i'm trying to do:

enum Value { Integer(i32), Boolean(bool) }

macro_rules! val {
    ($e:literal) => { Value::Integer($e) };
    ($e:literal) => { Value::Boolean($e) };
}

fn main() {
  let a = val!(43);
  let b = val!(false);
}

is there a way to define the type for the argument in the macro? e.g: ($e:literal: bool) => { Value::Boolean($e) }; ?

Thanks ๐Ÿ™‚