Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate a char onto a string in Rust?

Tags:

string

char

rust

I have tried using the to_string method on the char but this returns a &str when I need a String.

like image 579
unskilledidiot Avatar asked Jun 17 '16 19:06

unskilledidiot


People also ask

How do you concatenate characters in Rust?

Rust provides multiple ways to concatenate or join Strings, but the easiest of them is by using += operator.

Are strings mutable in Rust?

Rust owned String type, the string itself lives on the heap and therefore is mutable and can alter its size and contents.


1 Answers

Using String::push method is the easiest method:

let mut a_string = String::from("Hello World"); a_string.push('!'); 
like image 57
Chronium Avatar answered Sep 20 '22 07:09

Chronium