'How to bind function with placeholders
How can I do this: auto fn1 = bind(func, _1, 2, 3);
(C++ function binding with placeholders) in Rust (possibly without an intermediate closure)?
Solution 1:[1]
For a specific function, it's simple:
let bounded = move |param| func(param, 2, 3);
But the generic version is impossible to express in current Rust. C++ uses variadic templates for that, something Rust doesn't support (yet; it may in the future). You can try to emulate it using bunch of unstable feature and macros, but even then it won't probably apply to all cases, only to most of them.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chayim Friedman |