Learn Aero / References & Borrowing
References & Borrowing
Aero adopts an ownership + borrow-checking model similar to Rust: values use move semantics by default, and borrows come in immutable/mutable flavors.
Immutable Borrows &
fn read(p: &i64) -> i64 {
return *p; // 解引用
}
let x = 10;
print(read(&x)); // 10Mutable Borrows &mut
To modify the caller's variable, pass a mutable reference:
fn bump(p: &mut i64) {
*p = *p + 1;
}
let mut x = 10;
bump(&mut x);
print(x); // 11Basic Rules
*r&mut requires the variable itself to be writable (let mut)Why It's Needed
Function arguments passed by value are copies; references "borrow" the caller's data without copying. Aero manages "who owns, who borrows" at compile time to avoid dangling pointers and dangling references.