【发布时间】:2014-11-13 16:53:45
【问题描述】:
是否可以将闭包作为函数中的可选参数?
我需要这样的东西(伪代码):
fn function(x: int, optional expr |int| -> int) -> int
和用法是这样的:
// just the mandatory argument
n = function(z);
或可选:
// passed closure would be called inside the function
n = function(z, |x| x * x);
如果可能的话,我只是无法掌握正确的语法(会欣赏带有正确匹配表达式的完整示例)。
【问题讨论】:
标签: closures rust argument-passing optional-parameters optional