Skip to content

Interfaces

Interfaces can be defined, predictably, through the use of the interface keyword. Like so:

pub interface GeneralAllocator
    pub def alloc(a ref(GeneralAllocator), size usize) ref(void)|error
    pub def realloc(a ref(GeneralAllocator), ptr ref(void), size usize) ref(void)|error
    pub def free(a ref(GeneralAllocator), ptr ref(void))
end

All functions that are defined in the interface must be satisfied by types that implement that interface.

Types can derive from an interface through the use of the : operator.

An example of this in practice (the allocators standard library module) is as follows:

pub type HeapAllocator : GeneralAllocator
  # ...
end