flâneur — a map of the web's best reading

The program structure - Rust for C-Programmers

rust-for-c-programmers.com · 270 words · saved by 1 readers

Rust uses curly braces {} to define code blocks, similar to C. These blocks delimit scopes for functions, loops, conditionals, and other constructs. Variables declared within a block are local to that scope. Crucially, when a variable goes out of scope, Rust automatically calls its “drop” logic, freeing associated memory and releasing resources like file handles or network sockets—a core aspect of Rust’s resource management (RAII - Resource Acquisition Is Initialization). Unlike C, Rust generally does not require forward declarations for functions or types within the same module; you can call a function defined later in the file. This often encourages a top-down code organization. Important Exception: Variables must be declared or defined before they are used within a scope. Items like functions or type definitions can be nested within other items (e.g., helper functions inside another function) where it enhances organization.

Explore this link on the map →

saved by