Odak modu

Rust Fundamentals

Fundamental Types:Slices

Since having a memory management feature in Rust, there are 2 separate string types, one of which takes the letters as a vector and the other as a whole. In this way, we have the chance to manage the modifiable and non-modifiable partitions.

  • String is stored as a vector of bytes, it is always valid UTF-8 sequence. A String's size can be known or unknown at compilation time during initialization, but it can expand as the String's length exceeds its maximum. Strings have ownership. 
  • Slices allow you to refer to a continuous sequence of elements in a collection instead of the entire collection. Because a slice is a kind of reference, it does not have ownership. 

In performance-oriented languages, memory usage is minimized by reducing unnecessary storage. Data types such as String cause unnecessary memory usage as they freely use the Heap structure in all languages. For this reason, it is preferred to keep the events in the stack in rust and Heap is used when really necessary.

We can use &str to point to a specific part of an existing String instead of creating new String structures standing in the Heap. In this way, it does not require any allocation at runtime, and fixed-length &str cannot be resized.

You can find detailed further information from Rust Official documentation:

https://doc.rust-lang.org/book/ch04-03-slices.html 

Resources:

https://www.tutorialspoint.com/rust/rust_slices.htm 

https://www.educative.io/answers/what-is-the-slice-type-in-rust 

https://blog.logrocket.com/understanding-rust-string-str/ 

https://www.becomebetterprogrammer.com/rust-string-vs-str/

Background Pattern
Birlikte öğrenelim

Sektörde en çok aranan yazılım becerilerini kazan

Yapay zeka desteği, birebir mentörlük saatleri, canlı dersler ve senin için özel hazırlanmış içeriklerle eksiklerini tamamla, düzenli geri bildirimler al ve öğrenme sürecini en verimli hale getir.

Yunus Emre Kabakcı

Patika+ mezunu

Patika+ Fullstack Web Development Bootcamp mezunumuz Yunus Emre,

3 ay içinde Katar’dan aldığı teklif ile, global bir şirket olan Pavo Group’da işe başladı!


“İçerik zenginliği, mentor desteği, ileriye dönük bir network sağlaması ve dünyada en çok tercih edilen frameworkler üzerinden bir eğitim veriyor olması Patika+’ı tercih etmemin temel sebepleri oldu!“

Test

Yorumlar

Yorum yapabilmek için derse kayıt olmalısın!