piping/
lib.rs

1#![doc = include_str!("../README.md")]
2#![allow(clippy::tabs_in_doc_comments)]
3
4use proc_macro::TokenStream;
5
6mod pipe;
7mod tokens;
8mod utils;
9
10#[proc_macro]
11/// A macro that lets you use the pipeline operator with [Hack-like syntax](https://docs.hhvm.com/hack/expressions-and-operators/pipe).
12///
13/// ```rs
14/// fn add(a: usize, b: usize) -> usize {
15/// 	a + b
16/// }
17///
18/// fn orig_and_double(num: usize) -> (usize, usize) {
19/// 	(num, num * 2)
20/// }
21///
22/// let num = 4;
23///
24/// let piped = pipe! {
25/// 	num |> add(2, __) |> orig_and_double(__),
26/// 	(_, doubled) |> doubled as isize,
27/// };
28///
29/// assert_eq!(piped, 12isize);
30/// ```
31///
32/// You can pass any expression in as the input.
33///
34/// Notice that you can chain pipelines with `,`s to destructure the result of the previous pipeline.
35pub fn pipe(input: TokenStream) -> TokenStream {
36	pipe::pipe(input)
37}