Real programs.
Real shapes.

Each card below is a complete, self-contained Glide program. Copy it, save as example.glide, run with glide run example.glide.

HTTP router

Pattern-matched routes, path params, JSON responses — all stdlib.

import stdlib::http::*;
import stdlib::http::router::*;

fn user(req: *HttpRequest) -> HttpResponse {
    let id: string = req.param("id");
    return HttpResponse::ok()
        .json("{\"id\":\"".concat(id).concat("\"}"));
}

fn main() -> int {
    let r: *Router = Router::new();
    defer r.free();
    r.get("/users/:id", user);
    let res: !int = r.listen(8080);
    if !res.ok { println!("listen:", res.err); return 1; }
    return 0;
}

Worker pool

Four workers, one job queue, results streamed back through a result channel.

fn worker(jobs: chan<int>, out: chan<int>) {
    while let n = jobs.recv() { out.send(n * n); }
}

fn main() -> int {
    let j: chan<int> = make_chan(8);
    let o: chan<int> = make_chan(8);
    for _ in 0..4 { spawn worker(j, o); }
    for n in [1, 2, 3, 4, 5] { j.send(n); }
    j.close();
    return 0;
}

JSON, typed

@derive(JsonBind) generates parse + emit at compile time.

import stdlib::json::*;

@derive(JsonBind)
struct User {
    name: string,
    age:  int,
}

fn main() -> int {
    let u: User = User {
        name: "alice", age: 30,
    };
    println!(u.to_json());
    return 0;
}

File walker

Recursively list .glide files, count lines, print totals.

import stdlib::fs::*;

fn main() -> int {
    let files: *Vector<string> =
        fs_list_rec("src", ".glide");
    let mut total: int = 0;
    for i in 0..files.len() {
        total = total + fs_lines_count(files.get(i));
    }
    println!("files:", files.len(), "lines:", total);
    return 0;
}

WebSocket client

RFC 6455 handshake, match on the frame kind, send + receive.

import stdlib::net::ws::*;

fn main() -> int {
    let r: !*WebSocket = WebSocket::connect("wss://echo.example/ws");
    if !r.ok { println!("connect:", r.err); return 1; }
    let ws: *WebSocket = r.val;
    defer ws.close(1000, "bye");

    let _s: !int = ws.send_text("hello");
    let m: !*WsMessage = ws.recv();
    if m.ok { println!("got:", m.val.text); }
    return 0;
}

Inline assembly · RDTSC

Read the timestamp counter without an FFI hop. GCC-style operand constraints.

fn read_tsc() -> u64 {
    let lo: u32 = 0;
    let hi: u32 = 0;
    asm volatile { "rdtsc" : "=a"(lo), "=d"(hi) }
    return ((hi as u64) << 32) | (lo as u64);
}

fn main() -> int {
    println!("tsc:", read_tsc());
    return 0;
}

The repo's examples/ folder has dozens more — HTTP/2 servers, gzip streams, SMTP clients, tar extractors, and a full language tour.