-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
First of all, thank you for this library! The lack of this feature in rust prevents some useful applications of type computation.
Unfortunately, the following code, which uses structx! inside another macro, makes the compiler panic upon macro expansion with called `Result::unwrap()` on an `Err` value: Error("expected identifier or integer")
#![allow(semicolon_in_expressions_from_macros, unused_imports, dead_code)]
use bson::oid::ObjectId;
use std::fmt::Debug;
use structx::*;
#[derive(Debug, Default)]
struct Post {
id: ObjectId,
likes: u32,
user: String,
contents: String,
}
fn debug<T: Debug>(x: &T) {
println!("{:?}", x);
}
fn default<T: Default>() -> T {
Default::default()
}
macro_rules! projection {
($source:expr, $($field:ident)*, $last:ident) => {
$source.into_iter().map(|s|
structx! {
($($field: s.$field),*),
$last: s.$last
}
).collect::<Vec<_>>()
}
}
pub fn main() {
let ps: Vec<Post> = vec![default(), default()];
let ps = projection!(ps, likes, user);
debug(&ps);
}Complete log attached
log.txt
Metadata
Metadata
Assignees
Labels
No labels