Why Rust strings seem hard

Lately I’ve been seeing lots of anecdotes from people trying to get into Rust who get really hung up on strings (&str, String, and their relationship). Beyond Rust’s usual challenges around ownership, there can be an added layer of frustration because strings are so easy in the great majority of languages. You just add them together, split them, whatever! They’re primitives that you can do whatever you want with. For someone who’s only ever known this mental model (which is to say, never worked much with C/C++), using strings in Rust can be a rude awakening. They feel very complicated, have all these restrictions and extra steps, and it all just seems so unnecessary.

It’s a testament to Rust’s breadth and accessibility that even people who have never done low-level programming before are giving it a try. This is a good thing! But it comes with some extra challenges when you aren’t coming in with a background in C/C++.

“Go learn C++ and come back” isn’t a very reasonable solution to this problem, so I wanted to dig into one of the most common issues I see, and give a “cliff notes” explanation that hopefully makes Rust a bit more accessible to more people.

Let’s jump into it…

This thread was posted by one of our members via one of our news source trackers.

1 Like