#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(untagged))]
#[derive(Clone, Debug, Default)]
pub enum TileOutput {
#[default]
Skip,
Single(i32),
Random(Vec<i32>),
}
impl TileOutput {
pub const fn single(value: i32) -> Self {
TileOutput::Single(value)
}
pub const fn any(value: Vec<i32>) -> Self {
TileOutput::Random(value)
}
#[cfg(feature = "impl_fastrand")]
pub fn resolve(&self) -> Option<i32> {
self.resolve_with(&fastrand::Rng::default())
}
#[cfg(feature = "impl_fastrand")]
pub fn resolve_with(&self, rng: &fastrand::Rng) -> Option<i32> {
match self {
Self::Skip => None,
Self::Single(val) => Some(*val),
Self::Random(vals) => vals.get(rng.usize(0..vals.len())).copied(),
}
}
}