//! 成长领域错误。 //! //! 错误保持纯领域语义,例如章节参数非法、经验预算非法或用户/章节标识缺失。 use std::{error::Error, fmt}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum ProgressionFieldError { MissingUserId, MissingChapterId, InvalidChapterIndex, InvalidTotalChapters, InvalidLevel, InvalidEntryExitLevel, InvalidXpBudget, InvalidExpectedHostileDefeatCount, } impl fmt::Display for ProgressionFieldError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::MissingUserId => f.write_str("player_progression.user_id 不能为空"), Self::MissingChapterId => f.write_str("chapter_progression.chapter_id 不能为空"), Self::InvalidChapterIndex => { f.write_str("chapter_progression.chapter_index 必须大于 0") } Self::InvalidTotalChapters => f.write_str("chapter_progression.total_chapters 非法"), Self::InvalidLevel => f.write_str("player_progression.level 非法"), Self::InvalidEntryExitLevel => { f.write_str("chapter_progression.entry_level / exit_level 非法") } Self::InvalidXpBudget => f.write_str("chapter_progression 经验预算非法"), Self::InvalidExpectedHostileDefeatCount => { f.write_str("chapter_progression.expected_hostile_defeat_count 非法") } } } } impl Error for ProgressionFieldError {}