#[bot_new]Expand description
#[bot_new] macro adds initialization of field added by #[bot] macro.
Usage:
#[bot]
struct MyBot;
impl MyBot {
#[bot_new]
fn new() -> MyBot {
MyBot
}
}If your bot implements Default then you don’t need it, since Bot
implements Default too and will be filled automatically:
#[bot]
#[derive(Default)]
struct MyBot;
fn main() {
let bot = MyBot::default();
}#[bot]
#[derive(Default)]
struct MyBot {
field: Type,
field2: Type2,
field_n: TypeN,
}
impl MyBot {
fn new() -> MyBot {
MyBot {
field: Type::init(),
field2: Type2::init(),
..Default::default(),
}
}
}
fn main() {
let bot = MyBot::new();
}§Macro Inside
This:
#[bot]
struct MyBot;
impl MyBot {
#[bot_new]
fn new() -> MyBot {
MyBot
}
}Expands to:
struct MyBot {
_bot: Bot,
}
impl MyBot {
fn new() -> MyBot {
MyBot {
_bot: Default::default(),
}
}
}And this:
#[bot]
struct MyBot {
field: Type,
field2: Type2,
}
impl MyBot {
#[bot_new]
fn new() -> MyBot {
MyBot {
field: Type::init(),
field2: Type2::init(),
}
}
}Expands to:
struct MyBot {
_bot: Bot,
field: Type,
field2: Type2,
}
impl MyBot {
fn new() -> MyBot {
MyBot {
_bot: Default::default(),
field: Type::init(),
field2: Type2::init(),
}
}
}