我如何在 Rust 中创建一个接受任何类型或多个类型作为函数参数的函数?
我的第一种方法:
fn multiple_types(argument : _) {
println!("{}",argument);
}
我尝试将类型占位符“_”作为参数,但这是不允许的...
最佳答案
来自 the documentation :
We can write functions that take generic types with a similar syntax:
fn takes_anything<T>(x: T) { // do something with x }
关于rust - 我怎样才能创建一个接受任何类型的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30470172/