use crate::status::StatusDuration;
use crate::util::Id;
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::hash::Hash;
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct SimpleStatus<I, V> {
id: I,
effect: V,
max_duration: Option<StatusDuration>,
}
impl<I: Send, V: Copy> SimpleStatus<I, V> {
pub fn new(id: I, effect: V, max_duration: Option<StatusDuration>) -> Self {
Self {
id,
effect,
max_duration,
}
}
pub fn effect(&self) -> V {
self.effect
}
pub fn set_effect(&mut self, effect: V) {
self.effect = effect;
}
pub fn max_duration(&self) -> Option<StatusDuration> {
self.max_duration
}
}
#[cfg(not(feature = "serialization"))]
impl<I, V> Id for SimpleStatus<I, V>
where
I: Debug + Hash + Eq + Clone + Send,
{
type Id = I;
fn id(&self) -> &Self::Id {
&self.id
}
}
#[cfg(feature = "serialization")]
impl<I, V> Id for SimpleStatus<I, V>
where
I: Debug + Hash + Eq + Clone + Send + Serialize + for<'a> Deserialize<'a>,
{
type Id = I;
fn id(&self) -> &Self::Id {
&self.id
}
}