-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support concatenation in query*! macros #388
Comments
I don't dislike println!(concat!("Hello, ", stringify!(10))); |
There's a certain logical extreme where if we support |
Rust newbie here; I thought I could have a go at implementing this by patching if key == "source" {
enum SourceFragment { Str(LitStr), Ident(Ident) };
let mut fragments: Vec<SourceFragment> = Vec::new();
'source_parser: while !input.is_empty() {
fragments.push(match input.lookahead1() {
la if la.peek(Ident) => SourceFragment::Ident(input.parse()?),
la if la.peek(LitStr) => SourceFragment::LitStr(input.parse()?),
_ => break 'source_parser,
});
if !input.lookahead1().peek(Token![+]) {
break 'source_parser;
}
}
if fragments.len() == 0 {
return Err(syn::Error::new_spanned(key, "no source given"));
}
query_src = ???; But, as you can see, I have no idea how to "unquote" the fragments vec into a concrete Maybe https://github.com/Emoun/eager can be used to make this a bit easier? Edit: I realised what I thought was necessary was not, really, since just supporting |
I would like to use macros to generate calls to
query!
, e.g:For this, string concatination in the
query_as!
macro is necessarry. While the rust stdlib supports macro calls insideprintln!
(playground), @abonander suggested using+
for string concatenation, like in the example above.I believe this would tremendously reduce boilerplate code for many users, while still having all queries checked at compile time.
The text was updated successfully, but these errors were encountered: