-
Notifications
You must be signed in to change notification settings - Fork 14k
Description
As someone coming from dynamic as well as JVM languages, Rust strings were confusing. The Strings guide has very helpful intro material, but soon I found myself stumbling on more sophisticated use cases.
For example, let's say I want a struct where a member stores a list of strings:
pub struct DataRecord {
pub name: String,
pub tags: Vec<&'static str>
}The number of possible choices is bewildering. Do I use [String], Vec<String>, [&str], etc. etc.? Minimizing allocation is good, but structs are tricky because they might be kept around and bounced between multiple function calls before being disposed, or even kept in some other data structure. Also, each string within the list might come from a constant or not. Much more things to think about.
Anyways, the suggestion would be to cover a few examples like this where you use Strings in structs, vecs, arrays etc and go over what are best practices and common scenarios.