Répondre à ma propre question en double .
Cargo.toml:
[dependencies]
lazy_static = "1.4.0"
Crate root (lib.rs):
#[macro_use]
extern crate lazy_static;
Initialisation (pas besoin de bloc non sécurisé):
/// 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
};
...
ÉDITER:
J'ai réussi à le résoudre avec once_cell, qui n'a pas besoin 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
});