Attribute Macro vexide::main

source ·
#[main]
Expand description

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: A boolean value that toggles the vexide startup banner printed over serial. When false, the banner will be not displayed.
  • 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.screen, "Hello, vexide!").unwrap();
}

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

#[vexide::main(banner = false)]
async fn main(_p: Peripherals) {
   println!("This is the only serial output from this program!")
}

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!")
}