Skip to main content

pipe

Attribute Macro pipe 

Source
#[pipe]
Expand description

Defines a custom pipe transform used inside {{ expr | pipe }} interpolations.

Transforms a single-argument function into a struct implementing Pipe. The function receives a String (the stringified token) and returns any [quote::ToTokens] value.

§Examples

Custom pipe (name defaults to the function name):

#[zyn::pipe]
fn shout(input: String) -> syn::Ident {
    syn::Ident::new(&input.to_uppercase(), proc_macro2::Span::call_site())
}

let name = format_ident!("hello");
zyn::zyn!(static {{ name | shout }}: &str = "hi";)
// output: static HELLO: &str = "hi";

With a custom name alias:

#[zyn::pipe("yell")]
fn make_loud(input: String) -> syn::Ident { ... }

zyn::zyn!(fn {{ name | yell }}() {})

Chaining with built-in pipes:

zyn::zyn!(fn {{ name | snake | ident:"get_{}" }}() {})
// name = "HelloWorld" → fn get_hello_world() {}

§Debugging

Add debug to inspect the generated code as a compiler note diagnostic. Requires the ZYN_DEBUG environment variable to match the generated struct name (supports * wildcards).

#[zyn::pipe(debug)]
#[zyn::pipe(debug = "pretty")]       // requires `pretty` feature
#[zyn::pipe("alias", debug)]

Without ZYN_DEBUG, the debug argument is inert — safe to leave in source. See the debugging guide for details.