Beginner question; and a search couldn't find anything similar.
Background: I'm just practising functions in Rust by making a shuffling function. Program takes in any arguments and shuffles them and stores them in 'result
'
Question: I guess I can't use V<_>
in a function header so 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
Playground link
You would convert your function to a generic function:
fn shuffle<T>(args: Vec<T>) -> Vec<T> {
See it in the playpen: http://is.gd/MCCxal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With