Initial commit

This commit is contained in:
2026-04-14 03:44:59 +02:00
commit 0e908afbf7
33 changed files with 595 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
[package]
name = "workshop_macro"
version = "0.1.0"
edition = "2024"
[dependencies]
proc-macro2 = "1.0.106"
quote = "1.0.45"
reqwest = { version = "0.13.2", features = ["blocking"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
syn = "2.0.117"
[lib]
proc-macro = true
+37
View File
@@ -0,0 +1,37 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{LitStr, parse_macro_input};
// HINT: Maybe with creating some structs/enums that match with the format of schema.json?
// HINT: The word `type` is reserved in rust but can still be used if you write `r#type`
// HINT: Maybe implementing ToTokens can be useful?
// HINT: You can access fields in the quote macro (e.g. `#schema.name`) so instead first bind it
// to a local variable (e.g. `let name = &schema.name`).
// HINT: If you place use a string variable inside of the quote macro it will place it as a
// string (e.g. "User"). You need to first create a syn::Ident
// (see: https://docs.rs/syn/latest/syn/struct.Ident.html)
// HINT: If you have a iterable of qoutes! you can use and expand this in another quote macro
// with `#(#fields),*`, similar to how it works with declarative macros.
// HINT: Since the macro will be placed in the context of the "callsite" it is best to use the
// fully qualified path (e.g. `serde::Deserialize`), otherwise the user of the macro needs to
// manually add `use serde::Deserialize` to their file.
#[proc_macro]
pub fn from_schema(input: TokenStream) -> TokenStream {
let url = parse_macro_input!(input as LitStr).value();
let schema = reqwest::blocking::get(url).unwrap().text().unwrap();
// TODO: Print out the received schema text during compilation
println!("{schema:#?}");
quote! {
// TODO: Generate a struct based on the downloaded schema
}
.into()
}