Day 2: Primitive Types
EasyTypesNumbersTuples

Day 2: Primitive Types

Today we explore Rust's primitive types - the building blocks of all data in Rust.

What You'll Learn

  • Integer types (i32, u64, etc.)
  • Tuples and destructuring
  • Basic arithmetic operations
  • Return values from functions

Rust's Integer Types

SignedUnsignedSize
i8u88-bit
i16u1616-bit
i32u3232-bit
i64u6464-bit
i128u128128-bit

For Solana development, u64 is commonly used for token amounts (lamports), and u8 for single-byte flags.

Tuples

Tuples group multiple values of different types:

let point = (10, 20);           // type: (i32, i32)
let (x, y) = point;             // destructuring
println!("x: {}, y: {}", x, y);

The Task

Implement calculate(a, b) that returns a tuple of (sum, product).

Requirements

  • Take two i32 parameters
  • Return (a + b, a * b) as a tuple
  • The test uses (7, 6) expecting (13, 42)

Hints

  • Return a tuple with parentheses: (value1, value2)
  • No semicolon on the last expression = return value
Language: Rust
1
2
3
4
5
6
7
8
9
10
11
12
Output
Run to see the result here.
    Day 2: Primitive Types · RUST Challenge | learn.sol