module stack ; // Above: the parameterized type is applied to the entire module. import std::mem; struct Stack { usize capacity; usize size; Type* elems; } // The type methods offers dot syntax calls, // so this function can either be called // Stack.push(&my_stack, ...) or // my_stack.push(...) fn void Stack.push(Stack* this, Type element) { if (this.capacity == this.size) { this.capacity *= 2; this.elems = mem::realloc(this.elems, $sizeof(Type) * this.capacity); } this.elems[this.size++] = element; } fn Type Stack.pop(Stack* this) { assert(this.size > 0); return this.elems[--this.size]; } fn bool Stack.empty(Stack* this) { return !this.size; }