Is there any way to unpack an iterator into a tuple?
问题 Is there any way to accomplish something like the following: let v = vec![1, 2, 3]; let (a, b) = v.iter().take(2); Such that a = 1 and b = 2 at the end? I know I could just use a vector but I would like to have named variables. 回答1: This may not be exactly what you asked for, but I suppose you rarely want to convert an arbitrarily large vector to a tuple anyway. If you just want to extract the first few elements of a vector into a tuple, you can do so using slice pattern matching : fn main()