Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 987 Bytes

concatenate-vectors-of-string.md

File metadata and controls

31 lines (21 loc) · 987 Bytes
title timestamp author published description tags todo
Concatenate vectors of strings (merge vectors, join vectors)
2024-03-24 15:30:01 -0700
szabgab
true
I searched for joining vectors togehter, but apparently the function I needed is called concat.
concat
vec!
clone
Unclear why the string seem to move on merge

{% include file="examples/concatenate-vectors-of-string/src/main.rs" %}

In the first example (the concat function) we simply join the vectors together using the concat method. In this example we don't try to use the original vectors after the concatenation.

In the second example (the concat_and_use function) we want to use one of the original vectors after we concatenated them. This creates a compilation errro:

borrow of moved value: `birds`

and the compler suggests the use of the clone to copy the content of the vector. This solves the problem.