Lesson 3: Ownership, transfer, and borrowing
The heart of Arandu: linear ownership with own and ref.
Goal
In one sentence: understand who owns a value and how to pass data without copying.
Code
import io
struct Message {
text: str
priority: int
}
public func send(from: own Message) {
// here, "from" owns the Message
io.println(from.text)
}
public func read(from: ref Message) {
// here, "from" borrows the Message without taking ownership
io.println(from.text)
}
owntransfers ownership. Whoever receives becomes the owner and is responsible for freeing.refborrows without copying. The borrower does not lose the value — it just lends it temporarily.
Read the signature as a flow rule: send consumes the message; after the call, the caller cannot use that same message. read receives a temporary reference; after the call, the owner can still use the value. own therefore controls transfer, while ref controls access without copying.
Try it
Pass the same Message to send and then try to use it again. The compiler will show you that ownership was moved — and that is exactly what prevents use-after-free.
This is where Arandu saves you from a segfault: you cannot use a value after you have given up ownership. The error appears at compile time, not on a server in production.
No explicit lifetimes in the MVP. The rule is simple: either you own (own), or you borrow (ref). The simplicity is deliberate — the compiler does the rest of the bookkeeping.
This is the linear ownership transfer model: memory safety without a garbage collector.