#[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. Whenenabled = falsethe banner will be disabled.themecan be set to a customBannerThemestruct.code_sig: Allows using a customCodeSignaturestruct 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.
use std::fmt::Write;
use vexide::prelude::*;
#[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:
use vexide::prelude::*;
#[vexide::main(banner(enabled = false))]
async fn main(_p: Peripherals) {
println!("This is the only serial output from this program!")
}use vexide::{prelude::*, 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.
use vexide::{
prelude::*,
program::{CodeSignature, ProgramOptions, ProgramOwner, ProgramType},
};
static CODE_SIG: CodeSignature = CodeSignature::new(
ProgramType::User,
ProgramOwner::Partner,
ProgramOptions::empty(),
);
#[vexide::main(code_sig = CODE_SIG)]
async fn main(_p: Peripherals) {
println!("Hello world!")
}