Attributes
An attribute attaches metadata to a declaration, written as an #Name(...) attribute call on the line before the item it annotates. Attributes instruct the compiler — to link a foreign library, fix a calling convention, or flag a function at its call sites — without changing the declaration's own code.
#Link("Kernel32.dll")
extern func Beep(freq: uint32, duration: uint32) -> bool32;
Multiple attributes may be stacked before a single declaration; each applies independently.
#NoReturn()
#Warn("prefer Exit(); Abort() skips destructors")
func Abort();
Available Attributes
| Attribute | Purpose |
|---|---|
#Link | Link an extern function to a native library |
#Abi | Select a declaration's calling convention |
#Warn | Emit a compiler warning at every call site |
#Error | Emit a compiler error at every call site |
#NoReturn | Declare that a function never returns to its caller |
#Allow | Suppress a specific lint on the declaration |
Not an Attribute: Platform Selection
Restricting code to an operating system is not an attribute. Use conditional compilation instead — when #target.os == .Windows { ... } — which removes the untaken code before analysis rather than annotating a declaration.
See Also
- Conditional Compilation — the replacement for platform attributes
- Foreign Function Interface — where
#Linkis used - Functions — the declarations attributes most often annotate
Intrinsics
An intrinsic is a value or function whose meaning the compiler supplies directly — there is no Rux body to write, because the compiler knows the answer. The build context (#target, #build, #compiler, #source, #config) is built entirely from intrinsics, and a handful of standard-library routines are intrinsics too.
Link
Names the native library an extern function is imported from, and optionally the exported symbol to bind to. The operating system loader resolves the library by name at run time.