Data types - Rust for C-Programmers
Rust is a statically typed language, meaning the type of every variable must be known at compile time. The compiler can often infer the type, but you can also provide explicit type annotations. Once assigned, a variable’s type cannot change. Rust offers a standard set of primitive types: In addition to value types like i32, Rust also supports references—safe, managed pointers that refer to data stored elsewhere in memory. Similar to C pointers, references hold the address of a value, introducing a level of indirection. Rust references can be either immutable or mutable, allowing temporary access to data without transferring ownership or making a copy. This is especially useful for passing data to functions efficiently. To create a reference, Rust uses the & operator for immutable access and &mut for mutable access. The * operator can be used to access (dereference) the value behind a reference, although in many cases this happens implicitly. References are covered in more depth in Chap
Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help 2.5 Data Types and Annotations Rust is a statically typed language, meaning the type of every variable must be known at compile time. The compiler can often infer the type, but you can also provide explicit type annotations. Once assigned, a variable’s type cannot change. 2.5.1 Primitive Data Types Rust offers a standard set of primitive types: Integers: Signed (i8, i16, i32, i64, i128, isize) and unsigned (u8, u16, u32, u64, u128,…
saved by
related reading
- Summary - Rust for C-Programmersrust-for-c-programmers.com
- Summary - Rust for C-Programmersrust-for-c-programmers.com
- Summary - Rust for C-Programmersrust-for-c-programmers.com
- Constants and statics - Rust for C-Programmersrust-for-c-programmers.com
- The program structure - Rust for C-Programmersrust-for-c-programmers.com
- Rust for C programmers - Rust for C-Programmersrust-for-c-programmers.com
- Memory safety and ownership - Rust for C-Programmersrust-for-c-programmers.com
- Summary - Rust for C-Programmersrust-for-c-programmers.com
- What makes Rust special - Rust for C-Programmersrust-for-c-programmers.com
- Moves, cloning, and copying - Rust for C-Programmersrust-for-c-programmers.com
- Summary - Rust for C-Programmersrust-for-c-programmers.com
- Why Rust - Rust for C-Programmersrust-for-c-programmers.com