Skip to main content

Type System

Zynx features a statically checked type system optimized for performance, safety, and C interoperability.


Primitive Types

Integers

TypeSizeMinimumMaximum
i88-bit−128127
i1616-bit−32,76832,767
i3232-bit−2,147,483,6482,147,483,647
i6464-bit−9,223,372,036,854,775,8089,223,372,036,854,775,807
i128128-bit−2¹²⁷2¹²⁷ − 1
u88-bit0255
u1616-bit065,535
u3232-bit04,294,967,295
u6464-bit018,446,744,073,709,551,615
u128128-bit02¹²⁸ − 1
isizepointer-sizedplatform-dependentplatform-dependent
usizepointer-sized0platform-dependent

isize and usize are 32-bit on 32-bit platforms and 64-bit on 64-bit platforms.

Floating-Point

TypeSizePrecisionRange (approx.)
f1616-bit~3 decimal digits±65,504
f3232-bit~7 decimal digits±3.4 × 10³⁸
f6464-bit~15 decimal digits±1.8 × 10³⁰⁸
f128128-bit~34 decimal digits±1.2 × 10⁴⁹³²

Built-in Types

TypeSizeDescription
bool1 bytetrue or false
str16 bytes (slice)Immutable UTF-8 string; .length returns scalar count, .size returns byte count
void0 bytesAbsence of a value; used as function return type

Memory Types

References (&T)

  • Statically tracked borrows, either immutable (const &T) or mutable (&T).

Unique Pointers (Unique<T>)

  • Heap-allocated, single-owner value.
  • Created with Unique(value), which allocates and initializes the value on the heap.
  • Automatically freed when the owning scope ends.
  • Supports auto-deref: fields and methods of T can be accessed directly through Unique<T>.
  • Implicitly coerces to &T when passed where a reference is expected.
  • Has move semantics — assigning or returning a Unique<T> transfers ownership.
  • Unique<Unique<T>> and Unique<&T> are not allowed.
struct Buffer {
data: u8[256],
}

fn make_buffer() -> Unique<Buffer> {
return Unique(Buffer { data: [0; 256] });
}

fn main() {
let buf = make_buffer();
// buf.data is accessible via auto-deref
// buf is freed when main returns
}

Raw Pointers (*T)

  • Native C-style pointers, nullable by default.
  • Supports pointer arithmetic: p + n, p - n.

Collections

Arrays and Slices

  • T[]: Slice (pointer + length) with bounds-checked indexing.
  • T[N]: Sized array where the length is part of the type.
  • .length: Returns the number of elements.
  • == / !=: Sized arrays of the same type and length support element-wise equality comparison.

Tuples

  • Ordered collections: (i32, str).
  • Supports destructuring: let (x, y) = get_pair();.

Type Aliases and Distinct Types

Aliases (type)

  • Transparent names for existing types.
type Buffer = u8[];

Distinct Types (distinct)

  • Nominal types with the same runtime layout as their base type, but without implicit conversion.
type UserID = distinct u64;

let user = 42 as UserID;
let raw = user as u64; // Explicit cast required

Custom Types

Structs

  • Defined with struct. Support fields, methods, and visibility attributes (@private, @readonly).
  • See Structs.

Enums

  • Defined with enum. Variants can carry data.
  • See Enums.

Error Unions (T!)

  • Holds either a value of type T or an error.
  • Handled via try and catch.
  • See Error Handling.