diff options
| author | Mica White <botahamec@outlook.com> | 2026-05-21 18:50:06 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-05-21 18:50:06 -0400 |
| commit | 868329539613b40b48565c6bf11fd4920beaacee (patch) | |
| tree | 481ab2e75eb6d5d4d7c34cdebff8d036e4d34f31 /varihappy-macros/src | |
| parent | ea98969d350109487a42a01f0e5ef08afa4b01ac (diff) | |
Diffstat (limited to 'varihappy-macros/src')
| -rw-r--r-- | varihappy-macros/src/lib.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/varihappy-macros/src/lib.rs b/varihappy-macros/src/lib.rs index 3b1cc29..1d519c2 100644 --- a/varihappy-macros/src/lib.rs +++ b/varihappy-macros/src/lib.rs @@ -212,3 +212,27 @@ pub fn tuple_len(input: TokenStream) -> TokenStream { let len = Literal::usize_unsuffixed(tuple.elems.len()); quote! { #len }.into() } + +struct ArrayTuple { + ty: syn::Type, + count: syn::LitInt, +} + +impl syn::parse::Parse for ArrayTuple { + fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { + let ty = input.parse()?; + input.parse::<syn::Token![;]>()?; + let count = input.parse()?; + + Ok(Self { ty, count }) + } +} + +#[proc_macro] +pub fn array_tuple(input: TokenStream) -> TokenStream { + let ast = syn::parse_macro_input!(input as ArrayTuple); + + let types = (0..ast.count.base10_parse::<u128>().unwrap()).map(|_| ast.ty.clone()); + + quote! { (#(#types,)*) }.into() +} |
