January 2019
Beginner to intermediate
554 pages
13h 31m
English
Another source of confusion when dealing with strings in Rust is when concatenating two strings. In other languages, you have a very intuitive syntax for joining two strings. You just do "Foo" + "Bar" and you get a "FooBar". Not quite the case with Rust:
// string_concat.rsfn main() { let a = "Foo"; let b = "Bar"; let c = a + b;}
If we compile this, we get the following error:

The error message is really helpful here. The concatenation operation is a two step process. First, you need to allocate a string and then iterate over both of them to copy their bytes to this newly allocated string. As such, there's an implicit heap ...
Read now
Unlock full access