From 2d7d6cf641196549de5d3d87ebead36509405ab6 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Thu, 30 Jan 2025 22:02:07 -0500 Subject: [PATCH] fix: Better enforce typing for commands --- macro/src/pipe.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/macro/src/pipe.rs b/macro/src/pipe.rs index d2052ed..ca1853f 100644 --- a/macro/src/pipe.rs +++ b/macro/src/pipe.rs @@ -6,7 +6,7 @@ use syn::{ Error, Token, }; -use crate::{cmd::Value, macros::enum_to_tokens}; +use crate::cmd::Value; pub struct Pipe { stdin: Option, @@ -47,7 +47,7 @@ impl ToTokens for Pipe { let first_command = commands_iter.next().unwrap(); let initial = quote! { - let mut _c_0 = #first_command; + let mut _c_0: #first_command; _c_0.stdout(::std::process::Stdio::piped()); _c_0.stdin(::std::process::Stdio::piped()); let mut _child_0 = _c_0.spawn()?; @@ -95,7 +95,7 @@ impl ToTokens for Pipe { }); } - let mut #com_ident = #command; + let mut #com_ident: #command; #com_ident.stdout(::std::process::Stdio::piped()); #com_ident.stdin(::std::process::Stdio::piped()); @@ -171,4 +171,21 @@ impl Parse for CommandExpr { } } -enum_to_tokens! {CommandExpr: Macro, Reference, Function, Block} +impl ToTokens for CommandExpr { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + tokens.extend(match self { + Self::Macro(macr) => quote! { + ::std::process::Command = #macr + }, + Self::Reference(refer) => quote! { + &mut ::std::process::Command = #refer + }, + Self::Function(fun) => quote! { + ::std::process::Command = #fun + }, + Self::Block(block) => quote! { + ::std::process::Command = #block + }, + }); + } +}