Skip to content

Types

Redstone supports all Rust primitive types.

Integers

TypeSizeRange
i88-bit−128 … 127
i1616-bit−32 768 … 32 767
i3232-bit−2 147 483 648 … 2 147 483 647
i6464-bit−9.2×10¹⁸ … 9.2×10¹⁸
i128128-bitvery large
isizepointerplatform-dependent
u88-bit0 … 255
u1616-bit0 … 65 535
u3232-bit0 … 4 294 967 295
u6464-bit0 … 1.8×10¹⁹
u128128-bitvery large
usizepointerplatform-dependent

Integer literals are written as plain decimal numbers: 42, 0, 255.

Floating point

TypeSize
f3232-bit
f6464-bit

Float literals require a decimal point: 3.14, 0.5, 1.0.

Boolean

bool — either true or false.

red
let flag = true;
let other = false;

Char

char — a Unicode scalar value (4 bytes, stored as u32).

Literals use single quotes:

red
let letter = 'A';
let emoji  = '\u{1F600}';

print outputs the numeric code point value.

Unit

() — the unit type. Its only value is (). Used as the return type of functions that produce no value.

red
fn greet() -> () {
    print(72);  // 'H'
}

Default type

When no type annotation is written, the type defaults to i64 for backwards compatibility.

Type annotations

Type annotations are required wherever the type cannot be inferred from the value alone.

  • Float literals (3.14) default to f64; use f32 annotation to override
  • bool, char, () literals are always unambiguous
  • Integer literals are ambiguous — a type annotation or context is required:
red
let x: i32 = 10;        // annotation on let
let y: i64 = x * 2;     // 2 is resolved from x's type
let z = square(9);      // 9 is resolved from the param type of square

Function parameters always require a type annotation. Return type is optional and defaults to ():

red
fn add(a: i32, b: i32) -> i32 {
    return a + b;
}

Released under the MIT License.