Understanding Strings in Rust - String vs &str

preview_player
Показать описание
In this video, we are going to explore the difference between String and &str in Rust, as well as different tips to use them.

Thank you very much for watching! If you liked the video, please consider subscribing to the channel :)

Topics:
00:00 Introduction
00:44 Strings in memory
01:30 Trim operation
02:00 Trim in Rust
02:34 &str
02:48 When an allocation is needed
03:25 String literals
04:04 String vs &str
05:14 Converting between String and &str
05:39 Strings in function signatures
06:17 Conclusion

Or follow me on:

Рекомендации по теме
Комментарии
Автор

00:48 actually string literals like the one you have on your example are stored on the static memory along with the program binary in the code segment, to have a string in the heap you need to use the String type.

codeshowbr
Автор

does Rust do any small string optimization - like the C++ std::string implementations usually do? (Will store the string entirely in stack memory if is small enough to fit)

TheSulross
Автор

Crystal clear explanations! Thank you!!!

docomodocomol
Автор

Really helpful 👍 thanks for the explanation

alfianandi
Автор

Questa serie di video è davvero ben fatta, complimenti. Spero che aggiungerai altri video con argomenti più complessi di questo linguaggio perchè li spiegi davvero molto bene. Grazie per aver disattivato il plugin per rust di visual code perchè in questo modo il codice che mostri è molto più chiaro e guardando il video non si è distratti da tutti i messaggi invasivi che crea il plugin ogni volta che muovi il mouse sopra una parola. Scelta molto intelligente.

eugeniogonzato
Автор

I want to understand that when should you use heap vs stack in Rust? This is similar case in array vs vector. Can you please help...

RahulAhire
Автор

Sorry to bother, but what is your sound set up (mic, interface, etc)? Sounds really good. Great video by the way!

Felipe-
Автор

Are you gonna start posting regularly again?

Mal-nfsp
Автор

3:58 please explain why i isnt known at compile time 😮

ojochegbe_
Автор

What do you mean when you say the string is stored on the binary itself?

ninjarogue
Автор

Are you by any chance related to Neymar

tabaicanking
Автор

Never used var in my python programs! Guess ya learn something new everyday hey?
/s
😂

Hellbending