我很好奇 Rust 是否像 C# 一样支持协变和逆变,
例如,在 C# 中,有
delegate
Func
:
delegate TResult Func<in T, out TResult>(T arg);
object F1(string s)
{
return null;
}
string F2(object o)
{
return o.ToString();
}
// it's fine to do this
Func<string, object> f1 = F1;
Func<object, string> f2 = F2;
f1 = f2;
var o = f1("STR");
那么,在 rust lang 中做这些事情怎么样?有人可以发布一些相关的 Rust 代码吗 rust 中的协变和逆变,谢谢