Respondendo minha própria pergunta duplicada .
Cargo.toml:
[dependencies]
lazy_static = "1.4.0"
Raiz da caixa (lib.rs):
#[macro_use]
extern crate lazy_static;
Inicialização (sem necessidade de bloqueio inseguro):
/// EMPTY_ATTACK_TABLE defines an empty attack table, useful for initializing attack tables
pub const EMPTY_ATTACK_TABLE: AttackTable = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
lazy_static! {
/// KNIGHT_ATTACK is the attack table of knight
pub static ref KNIGHT_ATTACK: AttackTable = {
let mut at = EMPTY_ATTACK_TABLE;
for sq in 0..BOARD_AREA{
at[sq] = jump_attack(sq, &KNIGHT_DELTAS, 0);
}
at
};
...
EDITAR:
Consegui resolver com once_cell, que não precisa de macro.
Cargo.toml:
[dependencies]
once_cell = "1.3.1"
square.rs:
use once_cell::sync::Lazy;
...
/// AttackTable type records an attack bitboard for every square of a chess board
pub type AttackTable = [Bitboard; BOARD_AREA];
/// EMPTY_ATTACK_TABLE defines an empty attack table, useful for initializing attack tables
pub const EMPTY_ATTACK_TABLE: AttackTable = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
/// KNIGHT_ATTACK is the attack table of knight
pub static KNIGHT_ATTACK: Lazy<AttackTable> = Lazy::new(|| {
let mut at = EMPTY_ATTACK_TABLE;
for sq in 0..BOARD_AREA {
at[sq] = jump_attack(sq, &KNIGHT_DELTAS, 0);
}
at
});