use super::PluginEffectCommitError;
use std::{
fmt::{Debug, Display, Formatter},
num::NonZeroUsize,
};
pub const DEFAULT_PLUGIN_EFFECT_LIMIT: usize = 256;
#[derive(Clone, Copy, Eq, PartialEq)]
pub enum PluginEffectBatchLimitField {
MaxEffects,
}
impl PluginEffectBatchLimitField {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::MaxEffects => "max_effects",
}
}
}
impl Display for PluginEffectBatchLimitField {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}
impl Debug for PluginEffectBatchLimitField {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct PluginEffectBatchLimit {
max_effects: NonZeroUsize,
}
impl PluginEffectBatchLimit {
pub const fn try_new(max_effects: usize) -> Result<Self, PluginEffectCommitError> {
match NonZeroUsize::new(max_effects) {
Some(max_effects) => Ok(Self { max_effects }),
None => Err(PluginEffectCommitError::ZeroLimit {
field: PluginEffectBatchLimitField::MaxEffects,
}),
}
}
#[must_use]
pub const fn max_effects(self) -> usize {
self.max_effects.get()
}
#[must_use]
pub(in crate::plugin::host::effect) const fn max_effects_limit(self) -> NonZeroUsize {
self.max_effects
}
}
impl Default for PluginEffectBatchLimit {
fn default() -> Self {
Self::try_new(DEFAULT_PLUGIN_EFFECT_LIMIT).expect("default effect limit should be non-zero")
}
}