Skip to main content

Types

Oxide uses familiar type names inspired by Swift's type system while maintaining full compatibility with Rust's type system.

Platform-Native Types

These types have platform-dependent sizes (32-bit or 64-bit depending on the target):

OxideRustDescription
IntisizePlatform-native signed integer
UIntusizePlatform-native unsigned integer
let count: Int = 42
let size: UInt = 100

Transpiles to:

let count: isize = 42;
let size: usize = 100;

Sized Integer Types

These types have fixed sizes across all platforms:

OxideRustDescription
Int8i88-bit signed integer
Int16i1616-bit signed integer
Int32i3232-bit signed integer
Int64i6464-bit signed integer
Int128i128128-bit signed integer
UInt8u88-bit unsigned integer
UInt16u1616-bit unsigned integer
UInt32u3232-bit unsigned integer
UInt64u6464-bit unsigned integer
UInt128u128128-bit unsigned integer
let byte: UInt8 = 255
let bigNumber: Int64 = 9_223_372_036_854_775_807

Transpiles to:

let byte: u8 = 255;
let big_number: i64 = 9_223_372_036_854_775_807;

Floating Point Types

OxideRustDescription
Float32f3232-bit floating point
Float64f6464-bit floating point
let pi: Float64 = 3.14159
let approx: Float32 = 2.5

Transpiles to:

let pi: f64 = 3.14159;
let approx: f32 = 2.5;

Special Types

OxideRustDescription
CharcharUnicode character
BoolboolBoolean value
Unit()Unit type (void equivalent)
Never!Never type (function diverges)
StringStringUTF-8 string
let letter: Char = 'A'
let flag: Bool = true
let nothing: Unit = ()

fn diverges(): Never {
panic!("This function never returns")
}

Transpiles to:

let letter: char = 'A';
let flag: bool = true;
let nothing: () = ();

fn diverges() -> ! {
panic!("This function never returns")
}

Nullable Types

Any type can be made nullable by appending ?:

let name: String? = "Alice"    // Some("Alice")
let empty: String? = null // None

Transpiles to:

let name: Option<String> = Some("Alice".to_string());
let empty: Option<String> = None;

See Null Safety for more details on working with nullable types.

Generics

Oxide supports generic type parameters for both functions and types.

Generic Functions (Kotlin-style)

Functions place generic parameters before the function name:

fn <T> identity(x: T): T { x }

fn <T, U> pair(a: T, b: U): (T, U) { (a, b) }

fn <T: Clone> duplicate(x: T): (T, T) { (x.clone(), x) }

Transpiles to:

fn identity<T>(x: T) -> T { x }

fn pair<T, U>(a: T, b: U) -> (T, U) { (a, b) }

fn duplicate<T: Clone>(x: T) -> (T, T) { (x.clone(), x) }

Generic Structs (Rust-style)

Structs place generic parameters after the name:

struct Wrapper<T>(value: T)

struct Container<T: Clone>(items: Vec<T>)

Transpiles to:

struct Wrapper<T> { value: T }

struct Container<T: Clone> { items: Vec<T> }

Lifetime Parameters

Oxide supports Rust's lifetime system. For simple cases, lifetimes are inferred automatically:

// Lifetime inferred - no annotation needed
struct Parser(source: &String)

// Explicit lifetime when needed
struct RefHolder<'a, T>(inner: &'a T)

fn <'a> first(items: &'a [Int]): &'a Int {
&items[0]
}

Transpiles to:

struct Parser<'a> { source: &'a String }

struct RefHolder<'a, T> { inner: &'a T }

fn first<'a>(items: &'a [isize]) -> &'a isize {
&items[0]
}

See Ownership - Automatic Lifetime Inference for details on when inference applies.

Const Generics

Const generics enable types parameterized by compile-time values:

struct Buffer<const CAP: UInt>(len: Int)

fn <const N: UInt> getSize(): UInt { N }

Transpiles to:

struct Buffer<const CAP: usize> { len: isize }

fn get_size<const N: usize>() -> usize { N }

See Also