Rux Std

Complete Library reference for Std — IO, Memory, System, Text, Types, Encoding, UUID, Collections, Sort, Hash, Math, Random, and Time. Every function, constant, and type documented with examples.

Common Patterns

Hello World
import Std::Io::PrintLine;

func Main() {
    PrintLine("Hello, World!");
}
Output
Hello, World!
Read and Format
import Std::Io::{ReadLine, PrintLine};
import Std::Text::Format;

func Main() {
    let name = ReadLine();
    let msg = Format(
        "Hello, {}!", name
    );
    PrintLine(msg);
}
String Building
import Std::StringBuilder;

func Main() {
    let builder =
        StringBuilder::New();
    builder.Append("Hello");
    builder.Append(' ');
    builder.Append("World");
    let text =
        builder.IntoString();
    PrintLine(text);
}
Output
Hello World
Memory Allocation
import Std::Memory;

func Main() {
    let ptr = Alloc(
        10 * sizeof<int32>
    ) as *int32;

    Zero(ptr,
        10 * sizeof<int32>
    );

    Free(ptr);
}
Error Handling
import Std::{Assert, Fatal};

func Main() {
    let config =
        LoadConfig();
    if config == null {
        Fatal(
            "config missing"
        );
    }

    Assert(config.valid,
        "invalid config");
}
Random Number
import Std::Random;

func Main() {
    let seed = 12345u64;
    let roll = RandomInt(
        1, 101, seed
    );

    let flip = RandomBool(
        seed
    );

    PrintLine("Roll: {}", roll);
    PrintLine("Heads: {}", flip);
}
Possible Output
Roll: 42 Heads: true
UUID Generation
import Std::UUID;
import Std::Io::PrintLine;

func Main() {
    let id = UUID::UuidV4();
    PrintLine("UUID: {}", id);
    PrintLine("Valid: {}",
        UUID::IsValidUuid(
            id.data, id.length
        ));
}
Possible Output
UUID: 550e8400-e29b-41d4-a716-446655440000 Valid: true
SHA-256 Hash
import Std::Hash::Sha256;
import Std::Io::PrintLine;

func Main() {
    let hash = Sha256::Hash(
        c8"Hello, World!"
    );
    PrintLine(hash);
}
Output
dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
Base64 Encoding
import Std::Base64;
import Std::Io::PrintLine;

func Main() {
    let enc = Base64::EncodeBase64(
        c8"Hello, World!", 13
    );
    PrintLine(enc);
    let dec = Base64::DecodeBase64(
        enc.data, enc.length
    );
    PrintLine(dec);
}
Output
SGVsbG8sIFdvcmxkIQ== Hello, World!
HashMap
import Std::HashMap;
import Std::Io::PrintLine;

func Main() {
    var map: HashMap;
    HashMap::Init(&map);
    let val: int = 42;
    map.Set(1, val as *opaque);
    PrintLine("Contains 1: {}",
        map.Contains(1));
    PrintLine("Get 1: {}",
        *(map.Get(1) as *int));
    map.Free();
}
Output
Contains 1: true Get 1: 42
Array Sorting
import Std::Sort;
import Std::Io::PrintLine;

func Main() {
    var arr: int[5] =
        [5, 3, 1, 4, 2];
    Sort::Sort(arr.data, 5);
    for v in arr {
        PrintLine(v);
    }
}
Output
1 2 3 4 5

Platform Support

Module Linux Windows BSD Illumos macOS
IO Planned
Memory Planned
System Planned
Text Planned
Types
Encoding
UUID
Collections
Sort
Hash
Utilities Planned