macro_rules! async_robot {
($rbt:ty) => { ... };
($rbt:ty, $init:expr) => { ... };
}
Expand description
Allows your async robot code to be executed by the pros kernel. If your robot struct implements Default then you can just supply this macro with its type. If not, you can supply an expression that returns your robot type to initialize your robot struct. The code that runs to create your robot struct will run in the initialize function in PROS.
Example of using the macro with a struct that implements Default:
use pros::prelude::*;
#[derive(Default)]
struct ExampleRobot;
#[async_trait]
impl AsyncRobot for ExampleRobot {
asnyc fn opcontrol(&mut self) -> pros::Result {
println!("Hello, world!");
Ok(())
}
}
async_robot!(ExampleRobot);
Example of using the macro with a struct that does not implement Default:
use pros::prelude::*;
struct ExampleRobot {
x: i32,
}
#[async_trait]
impl AsyncRobot for ExampleRobot {
async fn opcontrol(&mut self) -> pros::Result {
println!("Hello, world! {}", self.x);
Ok(())
}
}
impl ExampleRobot {
pub fn new() -> Self {
Self { x: 5 }
}
}
async_robot!(ExampleRobot, ExampleRobot::new());