#source v0.1.0

Source
Compile-time location of the expression that reads it.

Package: Rux

Definition

intrinsic #source: Source;

struct Source {
    line: uint;
    column: uint;
    file: Slice<char8>;
    fileName: Slice<char8>;
    filePath: Slice<char8>;
    function: Slice<char8>;
    module: Slice<char8>;
}

#source is a compile-time value describing where in the code it is read. Each reference resolves to the position of that reference, which makes it useful for logging, assertions, and diagnostics that want to report their own location.

Fields

FieldTypeDescription
lineuintLine number of the reference.
columnuintColumn number of the reference.
fileSlice<char8>Full file identifier.
fileNameSlice<char8>File name alone.
filePathSlice<char8>Path to the file.
functionSlice<char8>Enclosing function's name.
moduleSlice<char8>Enclosing module's name.

Example

import Core::{ #source };
import Io::PrintLine;

func Main() -> int {
    PrintLine("{}:{}", #source.fileName, #source.line);
    return 0;
}

See also