News for hackers. Stuff that matters.
Re:The Core of Rust by marcus_cemes on Thursday August 21, 2025 @04:24PM (#44977620)
To extend upon this, memory generally has a single owner. When it goes out of scope, it gets freed [1]. The drop() function, which appears analogous to free() in C/C++, is actually just an empty function who's sole purpose is to take ownership and make it go out of scope, which immediately frees the memory [2].

> This function is not magic; it is literally defined as: pub fn drop<T>(_x: T) {}

This is usually more deterministic than GC languages (no random pauses), but can be less efficient for highly nested data structures. It also makes linked lists impossible without using "unsafe rust", as it doesn't abide by the normal ownership rules.

[1]: https://doc.rust-lang.org/rust-by-example/scope/raii.html [2]: https://doc.rust-lang.org/std/mem/fn.drop.html

Re:The Core of Rust by sshine on Friday August 22, 2025 @02:41AM (#44981614)
Linked lists to arbitrary memory, yes. Linked list from a consecutive chunk of memory managed by a bump allocator: just as easy as any language, no need for unsafe.

Admittedly not the easiest language to make a linked list in.