Diagnostics v0.1.0

Source
Run-time assertions and panics that report and terminate, and the compile-time #Error and #Warn that reject or flag a configuration.

Assert

pub func Assert(condition: bool, message: char8[..])

Terminates the program unless condition holds. condition and message are read by value; nothing is returned and nothing is taken ownership of. message should say what was expected rather than what was found, since the value that failed is not printed. Reports the message, the enclosing function, and the file, line and column of the call, then terminates. Does not unwind: no destructor runs, and no caller observes the failure. Present in every build, so it is the right check for a contract that must hold in a released program. Runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
conditionboolwhat must hold
messagechar8[..]what to report when it does not

DebugAssert

pub func DebugAssert(condition: bool, message: char8[..])

Terminates the program unless condition holds, in builds that keep debug assertions. condition and message are read by value. Identical to Assert where it is kept, and removed entirely where it is not: a release build does not evaluate condition, so an argument with a side effect will not have it, and an expensive check costs nothing. Reports and terminates exactly as Assert does. Does not unwind. Runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
conditionboolwhat must hold
messagechar8[..]what to report when it does not

Panic

pub func Panic(message: char8[..])

Terminates the program, reporting message. message is read by value; this never returns. Use it where a case is unreachable by construction rather than unlikely — a caller who could have handled the failure should have been given a fallible T ! E instead. Reports the message, the enclosing function, and the file, line and column of the call, then terminates. Does not unwind: no destructor runs. Runs in constant time and allocates nothing.

Source

Parameters

NameTypeDescription
messagechar8[..]what to report before terminating

#Error

pub func #Error(message: char8[..])

Rejects the build where it is written, reporting message. message must be a string literal, since this is evaluated while compiling. Produces no runtime code and never returns a value. A directive inside a when branch that was not taken never fires. Cannot fail at run time, because it does not reach run time. Costs nothing in the built program.

Source

Parameters

NameTypeDescription
messagechar8[..]the diagnostic to emit at the call site

#Warn

pub func #Warn(message: char8[..])

Reports message as a compilation warning where it is written, without rejecting the build. message must be a string literal. Produces no runtime code. A directive inside a when branch that was not taken never fires, so a warning about one target does not appear when building for another. Cannot fail. Costs nothing in the built program.

Source

Parameters

NameTypeDescription
messagechar8[..]the diagnostic to emit at the call site