_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
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Rust Ownership System

17. 07. 2025 1 min read intermediate

Rust ownership system eliminates entire categories of bugs — use-after-free, double free, data races — at compile time.

Ownership Rules

  1. Each value has exactly one owner
  2. When the owner leaves scope, the value is freed
  3. Ownership moves during assignment

Move and Borrowing

fn main() { let s1 = String::from(“hello”); let s2 = s1; // s1 moved to s2, s1 no longer valid! // Borrowing — reference let s3 = String::from(“world”); let len = calculate_length(&s3); // Immutable borrow println!(“{s3} has length {len}”); // s3 still valid // 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”); }

Borrowing Rules

  • Any number of immutable references (&T)
  • OR one mutable reference (&mut T)
  • Never both simultaneously
  • References must be valid (lifetimes)

Key Takeaway

Ownership = memory safety without GC. Move, borrow (&), mutable borrow (&mut). The compiler is your friend.

rustownershipmemory safety
Share:

CORE SYSTEMS tým

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