Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I concatenate something to the front of a string?

I keep getting the error "Use of moved value".

let mut s = "s".to_string();
s = s + &s;
like image 253
Tyler Hilbert Avatar asked Mar 14 '23 22:03

Tyler Hilbert


1 Answers

Adding a solution to Chris Morgan's answer:

let s = "s";
let mut double_s = s.to_owned(); // faster, better than to_string()
double_s = double_s + s;

You could also use

double_s.push_str(s);

instead of the last line.

like image 165
llogiq Avatar answered Mar 18 '23 05:03

llogiq