我读了
如何在 Rust 中编写函数? https://stackoverflow.com/questions/45786955/how-to-compose-functions-in-rust
Rust 中的函数组合链 https://stackoverflow.com/questions/72597835/function-composition-chain-in-rust
我了解到在 Rust 中实现函数组合链相当困难,并且人们将宏与某些函数一起使用,但是,我想知道是否可以仅使用宏而不使用宏compose
从一开始就发挥作用。
I mean
compose!(f, g)
可以简单地改写为|x| g(f(x))
(只是另一种语法)
or
compose!(f, g, h)
可以类似地重写为|x| h(g(f(x)))
compose!(f, g, h, i)
可以类似地重写为|x| i(h(g(f(x))))
compose!(f, g, h, i,...)
可以类似地重写为|x| ...(i(h(g(f(x)))))
作为递归方式。
我猜这个递归宏不需要实际的函数组合函数。
我刚刚开始学习 Rust 宏,那么编写此代码的明智方法是什么?
附言。 Rust 中的宏类型推断是否可以正常工作?