parasyte / onlyargs

Only argument parsing! Nothing more.
MIT License
13 stars 2 forks source link

Can't set a default value for `bool` args in derive macro #16

Closed parasyte closed 7 months ago

parasyte commented 1 year ago

Boolean values true and false are not literals. They are idents: https://dev-doc.rust-lang.org/beta/proc_macro/struct.Literal.html

(emphasis added)

A literal string ("hello"), byte string (b"hello"), character ('a'), byte character (b'a'), an integer or floating point number with or without a suffix (1, 1u8, 2.3, 2.3f32). Boolean literals like true and false do not belong here, they are Idents.

The bug is here: https://github.com/parasyte/onlyargs/blob/f331a2ecea9a64830dd59d0996846bbd857baaed/onlyargs_derive/src/parser.rs#L119

It needs a fallback to check for true and false idents if the token is not a literal.

parasyte commented 11 months ago

String has the same kind of problem. The derive macro passes a string literal, but it wants a heap-allocated String. It needs to call .to_string() on whatever is provided in the #[default(...)] attribute.

parasyte commented 7 months ago

And PathBuf, too! Something like try_into() or parse() might work for all of these?