Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Public Assignments

Public assignments provide a value to the inner and the outer of a module.

test

mod my_module {
    pub mod sub_module {
        pub const TEXT = "Hello";
    }
}

std::print(my_module::sub_module::TEXT);

Restrictions

Not in workbenches

Using pub is not allowed within workbenches:

test

sketch MySketch() {
    pub const TEXT = "Hello"; // error
    std::print(TEXT);
}

MySketch();

Not in functions

test

fn f() {
    const MY_CONST = 1; // error: not allowed in functions
}
f();