Example:
let [a, b, c] = "lorem ipsum dolor sit amet"
.split(' ')
.next_n::<3>()
.unwrap();
assert_eq!((a, b, c), ("lorem", "ipsum", "dolor"));
Could this be implemented with min_const_generics
? Is something like this planned?
The alternative is much less elegant:
let mut iter = "lorem ipsum dolor sit amet".split(' ');
let a = iter.next().unwrap();
let b = iter.next().unwrap();
let c = iter.next().unwrap();
assert_eq!((a, b, c), ("lorem", "ipsum", "dolor"));
or requires allocating a Vec
:
let v = "lorem ipsum dolor sit amet"
.split(' ')
.take(3)
.collect::<Vec<_>>();
assert_eq!((v[0], v[1], v[2]), ("lorem", "ipsum", "dolor"));