home ~ projects ~ socials

Combine Two vecs In Rust

fn main() {
  let mut alfa = vec!["a".to_string(), "b".to_string(), "c".to_string()];
  let mut bravo = vec!["d".to_string(), "e".to_string(), "f".to_string()];

  alfa.append(&mut bravo);

  dbg!(alfa);
  dbg!(bravo);
}
Output:
[_active_nvim_run:7:3] alfa = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
]
[_active_nvim_run:8:3] bravo = []

Notes

  • There's also .extend() which can be used with references for things that implement copy. TODO is to make an example with that.
-- end of line --

References