Zum Inhalt springen
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

Rust Ownership systém

17. 07. 2025 1 Min. Lesezeit intermediate

Rust ownership systém eliminuje celé kategorie bugů — use-after-free, double free, data races — v compile time.

Ownership pravidla

  1. Každá hodnota má právě jednoho ownera
  2. Když owner opustí scope, hodnota se uvolní
  3. Ownership se přesouvá (move) při přiřazení

Move a borrowing

fn main() { let s1 = String::from(“hello”); let s2 = s1; // s1 moved to s2, s1 už neplatí! // Borrowing — reference let s3 = String::from(“world”); let len = calculate_length(&s3); // Immutable borrow println!(“{s3} has length {len}”); // s3 stále platí // Mutable borrow let mut s4 = String::from(“hello”); change(&mut s4); } fn calculate_length(s: &String) -> usize { s.len() } fn change(s: &mut String) { s.push_str(” world”); }

Pravidla borrowing

  • Libovolný počet immutable references (&T)
  • NEBO jedna mutable reference (&mut T)
  • Nikdy obojí současně
  • Reference musí být validní (lifetimes)

Klíčový takeaway

Ownership = memory safety bez GC. Move, borrow (&), mutable borrow (&mut). Compiler je váš přítel.

rustownershipmemory safety
Teilen:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.