Rust strings are hard

Published: 2022-06-25 10:30:30

I recently gave a Rust workshop to Kotlin and Swift developers. Strings in Rust are a really, really difficult topic for complete newcomers

Rust strings are hard

I recently gave a Rust workshop to Kotlin and Swift developers. Strings in Rust are a really, really difficult topic for complete newcomers because they're understood as a basic type whereas in Rust they require having read half the Rust book to grasp.

Consider: I can teach a lot of Rust basic with usize. Defining funcions, calling functions, enums because they're Copy and because there's only one type. String requires knowing about &str which requires knowing about deref which requires knowing about (&String -> &str), it also requires understanding lifetimes, moving, heap and stack, cloning. Then, if you want to work with the file system you also need to understand Paths, OsString and AsRef.

With Kotlin and Swift, for all these things, you really just need one type, String, and you handle it just like usize.

It is really a bid of a hurdle for new developers coming from higher level languages (especially if they just give it a quick try).