In Rust is there a simple way to split a vector like this:
let original_vec = vec![
(14, "Foo", 62.3),
(17, "Foo", 77.8),
(25, "Bar", 33.7),
(27, "Bar", 99.2),
(61, "Foo", 17.4),
(64, "Bar", 55.5),
(77, "Bar", 31.2),
];
into this:
let res = vec![
vec![
(14, "Foo", 62.3),
(17, "Foo", 77.8),
],
vec![
(25, "Bar", 33.7),
(27, "Bar", 99.2),
],
vec![
(61, "Foo", 17.4), // "Foo" again
],
vec![
(61, "Bar", 55.5), // A separate group of "Bars"
(77, "Bar", 31.2),
],
]
Just to clarify: I want to split my input vector by one of the fields in its elements. Only contiguous elements with the same field value must be put in a sub-vector. The "flattened" result vector must have the same order as the original vector.