Generics support
smokku opened this issue · comments
Is supporting generics in scope of this project?
With
#[derive(Debug, Clone, SerBin, DeBin, Default, PartialEq)]
pub struct Timestamped<T> {
inner: T,
timestamp: Timestamp,
}
I get:
error: proc-macro derive panicked
--> shared\src\timestamp.rs:221:24
|
221 | #[derive(Debug, Clone, SerBin, DeBin, Default, PartialEq)]
| ^^^^^^
|
= help: message: Unexpected data after end of the struct
They are, just not implemented yet
I started looking into this because I need it for https://github.com/expenses/goth-gltf/. Is there a canonical way to parse out generics in proc macros? I'm using this for now:
fn next_struct(mut source: &mut Peekable<impl Iterator<Item = TokenTree>>) -> Struct {
let struct_name = next_ident(&mut source).expect("Unnamed structs are not supported");
+ let has_generics = if let Some(_) = next_punct(&mut source) {
+ let generic = next_ident(&mut source);
+ if let Some(_) = next_punct(&mut source) {
+ let binding = next_ident(&mut source);
+ let next = next_punct(&mut source).unwrap();
+ if next == "=" {
+ let default = next_ident(&mut source);
+ next_punct(&mut source);
+ }
+ } else {
+ next_punct(&mut source);
+ }
+ true
+ } else {
+ false
+ };
+
This should all be handled now via a new parser, please open a new issue if you encounter problems with the new parser's support for generics