1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::Player;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Struct representing a tracker entry.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Entry<T> {
    /// Player this entry corresponds to.
    pub player: Player,

    /// Data associated with the player.
    pub data: T,
}

impl<T> Entry<T> {
    /// Creates a new entry.
    pub fn new(player: Player, data: T) -> Self {
        Self { player, data }
    }
}

impl<T> From<Player> for Entry<T>
where
    T: Default,
{
    fn from(player: Player) -> Self {
        Self::new(player, T::default())
    }
}