Edit: I found in the debugger, that the reason I was doing a stack overflow was because i was comparing
data_pool.people[player_i].amt_dice == 0
Because of this it called PartialEq
on Player
and my definition of PartialEq
for Player was recursive:
impl PartialEq for Player {
fn eq(&self, other: &Self) -> bool {
println!("did this");
self == other
}
}
So now I will have to figure out how to implement this. Thank you "jvcmarcenes".
--- Original Question ---
In my code, I am checking:
data_pool.people[player_i].amt_dice == 0
Where data_pool
is a struct with some data and vectors in it.
One vector in data_pool
is people.
By index, I am accessing the struct people
with index player_i
.
I am accessing the amt_dice
field from the Player
struct.
This gives me a stack overflow.
Here is my DataPool struct and it's defenition:
struct DataPool {
players_alive: usize,
current_bid : Option<Bid>,
people : Vec<Player>
}
My Player struct Defenition:
struct Player{
die_result: Vec<usize>,
amt_dice: usize,
ai: fn(&DataPool, &mut ThreadRng, &Dice) -> Action
}
How I'm initializing the two:
let mut data_pool: DataPool = DataPool {
players_alive: amt_players, current_bid: None,
people: vec![
Player::new(&d6, &mut rng, dpp, call_liar),
Player::new(&d6, &mut rng, dpp, call_liar)
]
};
I hope I have mentioned enough information, I didn't want to put the whole code up because it is quit big and messy. If you want me to show you the code, say the word, I'll edit this post.
I have no idea why I'm getting a stack overflow, I just know where it is happening due to some print debugging.