我读过
如何在Rust中撰写功能?
功能构成链中RUST
我学会了在Rust中实现功能组成链非常困难,人们将宏使用具有某种功能的宏,但是,我想知道是否只能在没有 compose> compose
的情况下使用宏首先功能。
我的意思是
compose!(f,g)
可以简单地将其重新列入 | x | g(f(x))
(只是另一种语法)
或
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 Macro,那么对此进行编码的明智方法是什么?
PS。类型推断与Rust的宏观合作良好吗?
I've read
How to compose functions in Rust?
Function composition chain in Rust
I've learned implementing a Function composition chain in Rust is rather difficult, and people use Macro with some function, however, I wonder if it's possible to use only a macro without a compose
function from the first place.
I mean
compose!(f, g)
can be simply reritten to |x| g(f(x))
(just another syntax)
or
compose!(f, g, h)
can be similarly rewitten to |x| h(g(f(x)))
compose!(f, g, h, i)
can be similarly rewitten to |x| i(h(g(f(x))))
compose!(f, g, h, i,...)
can be similarly rewitten to |x| ...(i(h(g(f(x)))))
as the recursive manner.
I guess this recursive macro does not need the actual function composition function.
I've just started learning Rust macro, so what would be the smart way to code this?
PS. Does the type-inference work fine with macro in Rust?
发布评论
评论(1)
是的,您只能使用宏只能做到这一点:
Yes, you can do that only using macros: