IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Mojo decorators

A Mojo decorator modifies or extends the behavior of a struct, function, or other declaration at compile time. You place the decorator on the line above the declaration it applies to, prefixed with @.

@fieldwise_init
struct Point:
var x: Float64
var y: Float64

After the @, a decorator is followed by a name, with optional arguments in parentheses. Each decorator goes on its own line. You can stack multiple decorators on a single declaration:

@fieldwise_init
@align(64)
struct CacheLine:
var data: SIMD[DType.float32, 16]

Decorators apply bottom-up: the one closest to the declaration is applied first.

Decorators

The following pages describe each built-in decorator with examples.

Decorator targets

Not every decorator works on every declaration. This table shows which decorators are valid on which targets.

Decoratorstructdefmethodtraitcomptimevarfield
@alignyes
@always_inlineyesyes
@compiler.registeryes
@__copy_captureyes
@deprecatedyesyesyesyesyes
@doc_hiddenyesyesyesyesyes
@explicit_destroyyes
@exportyes
@fieldwise_inityes
@implicityes
@no_inlineyesyes
@nonmaterializableyes
@parameteryes
@staticmethodyes