我做了很长一段时间的C#程序员,在Rust上玩得很开心,但我有一个关于反思的问题.也许在这种情况下我不需要反射,但考虑到 rust 迹是强类型的,我怀疑我需要反射(我肯定需要它在好的ol'C#中,保佑它的棉袜子).
我有这样的情况:
use std::collections::HashMap;
fn invoke_an_unknown_function(
hashmap: HashMap<String, String>,
// Something to denote a function I know nothing about goes here
) {
// For each key in the hash map, assign the value
// to the parameter argument whose name is the key
// and then invoke the function
}
我该怎么做?我猜我需要将某种类型的MethodInfo
作为第二个参数传递给函数,然后用它来获取参数,这些参数的名称是散列图中的键,并分配值,但我查看了反射API,发现了以下pre-Rust 1.0文档:
这些都不足以让我开始.我将如何实现上述功能?