[Web Feed] Recently I???ve been working on a project to surface census data via a GraphQL ...

Feed Supplier <[email protected]>
Newsgroups alt.comp.programming
Organization Usenet.Farm
Message-ID <[email protected]>
..API, mostly as a way to learn GraphQL. I did end up learning 



Recently I’ve been working on a project to surface census data via a GraphQL API, mostly as a way to learn GraphQL. I did end up learning GraphQL, but I also ended up learning a lot about proc macros. I was using Juniper, which creates a GraphQL schema using structs like this:



#[derive(GraphQLObject, Copy, Clone, Debug)]
struct Demographics {
    female: Option<i32>,
    male: Option<i32>,
}



The problem, is that the census data I was looking to surface had _way_ too many variables, I would have had to write out 207 structs, with a total of 352 fields. Here’s a 
gist.github.com/marcusbuffett/693026a0a8923bec98e67259f5e71a66: nice tree-view of the census data, courtesy of the 
github.com/birchb1024/frangipanni: frangipanni tool. Obviously, I didn’t want to write out all these structs and fields by hand, even with some fancy vim macros that would have been too much tedious work for a side project that’s supposed to be fun.

I dipped my toes into proc macros for the first time, and found they really weren’t that hard, but the resources out there are so scarce. All I wanted was a few examples of non-trivial macros, but I couldn’t find many. So this isn’t a full proc macros walkthrough, just a quick look at the macro I ended up writing for my use case.




Link 1


    
    An Incomplete Explanation of the Proc Macro That Saved Me 4000 Lines of Rust :: A blog  — Just a blog
    
: https://mbuffett.com/posts/incomplete-macro-walkthrough
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.