vexide_macro

Attribute Macro main

Source
#[main]
Expand description

vexide’s entrypoint macro

Marks a function as the entrypoint for a vexide program. When the program is started, the main function will be called with a single argument of type Peripherals which allows access to device peripherals like motors, sensors, and the display.

The main function must be marked async and must not be marked unsafe. It may return any type that implements Termination, which includes (), !, and Result.

§Parameters

The main attribute can be provided with parameters that alter the behavior of the program.

  • banner: Allows for disabling or using a custom banner theme. When enabled = false the banner will be disabled. theme can be set to a custom BannerTheme struct.
  • code_sig: Allows using a custom CodeSignature struct to configure program behavior.

§Examples

The most basic usage of the main attribute is to mark an async function as the entrypoint for a vexide program. The function must take a single argument of type Peripherals.

#[vexide::main]
async fn main(mut peripherals: Peripherals) {
    write!(peripherals.display, "Hello, vexide!").unwrap();
}

The main attribute can also be provided with parameters to customize the behavior of the program.

This includes disabling the banner or using a custom banner theme:

#[vexide::main(banner(enabled = false))]
async fn main(_p: Peripherals) {
   println!("This is the only serial output from this program!")
}
use vexide::startup::banner::themes::THEME_SYNTHWAVE;
#[vexide::main(banner(theme = THEME_SYNTHWAVE))]
async fn main(_p: Peripherals) {
   println!("This program has a synthwave themed banner!")
}

A custom code signature may be used to further configure the behavior of the program.

static CODE_SIG: CodeSignature = CodeSignature::new(
    ProgramType::User,
    ProgramOwner::Partner,
    ProgramFlags::empty(),
);
#[vexide::main(code_sig = CODE_SIG)]
async fn main(_p: Peripherals) {
   println!("Hello world!")
}