How to Avoid Unnecessary Clones in Rust

Prevent performance issues in Rust by using references and iterators to borrow data instead of creating expensive copies.

Avoid unnecessary clones by passing references (&T) or using iterators instead of copying owned data. Use &self in method signatures and iterate with for item in &collection to borrow elements rather than cloning them.

fn process(items: &[i32]) {
    for item in items {
        println!("Item: {}", item);
    }
}

fn main() {
    let data = vec![1, 2, 3];
    process(&data);
}