typst_macros

Attribute Macro scope

source
#[scope]
Expand description

Provides an associated scope to a native function, type, or element.

This implements NativeScope for the function’s shadow type, the type, or the element.

The implementation block can contain four kinds of items:

  • constants, which will be defined through scope.define
  • functions, which will be defined through scope.define_func
  • types, which will be defined through scope.define_type
  • elements, which will be defined through scope.define_elem
#[func(scope)]
fn name() { .. }

#[scope]
impl name {
    /// A simple constant.
    const VAL: u32 = 0;

    /// A function.
    #[func]
    fn foo() -> EcoString {
        "foo!".into()
    }

    /// A type.
    type Brr;

    /// An element.
    #[elem]
    type NiceElem;
}

#[ty]
struct Brr;

#[elem]
struct NiceElem {}