Placeholder type '_' is not valid in item label types
Initial question; and the search couldn't find anything like it.
Background: I'm just practicing functions in Rust by doing a shuffle function. The program takes any arguments, shuffles them and stores them in ' result
'
Question: I suppose I cannot use V<_>
in the function header, what would I use in this situation?
MCVE:
use std::io;
use std::cmp::Ordering;
use std::env;
fn main()
{
let mut result = shuffle(env::args().collect());
}//End of main
fn shuffle(args: Vec<_>) -> Vec<_>
{
let mut temp = Vec::with_capacity((args.capacity()));
while args.len() > 1
{
//LET N REPRESENT A RANDOM NUMBER GENERATED ON EACH ITERATION
let mut n = 2;
temp.push(args.swap_remove(n));
}
return temp;
}//End of shuffle function
+3
source to share
1 answer
You would convert your function to a generic function:
fn shuffle<T>(args: Vec<T>) -> Vec<T> {
Look in the manner: http://is.gd/MCCxal
+3
source to share