Rust Data Types — Scalar Types, Compound Types, Type Inference, and Casting
DodaTech
Updated 2026-06-28
1 min read
In this tutorial, you will learn about Rust Data Types. We cover key concepts, practical examples, and best practices to help you master this topic.
Rust data types include scalars (i32, f64, bool, char) and compounds (tuple, array) with type inference, explicit annotation, and casting.
What You'll Learn
- Scalar types: integers, floats, bool, char
- Compound types: tuples, arrays
- Type inference and annotation
- Type casting
Why It Matters
Rust's type system catches errors at compile time. DodaZIP uses fixed-size arrays for buffer management and tuples for coordinate pairs.
Real-World Use
Fixed-size buffers for I/O, coordinate pairs in graphics, configuration values, flag management.
fn main() {
// Scalar types
let a: i32 = -42;
let b: u64 = 100;
let c: f64 = 3.14;
let d: bool = true;
let e: char = 'R';
// Compound types
let tuple: (i32, f64, char) = (42, 3.14, 'R');
let (x, y, z) = tuple;
println!("{}, {}, {}", x, y, z);
let array: [i32; 5] = [1, 2, 3, 4, 5];
println!("First: {}", array[0]);
println!("Length: {}", array.len());
// Type casting
let val = 65.4321_f64;
let int_val = val as i32;
println!("Cast: {}", int_val);
}
← Previous
Rust Variables and Mutability — Understanding Ownership, Shadowing, and Constants
Next →
Rust Functions — Function Definitions, Parameters, Return Values, and Expressions
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro