A pit full of rusty nails
at main 26 lines 663 B view raw
1use rand::seq::WeightError; 2 3#[derive(Debug, Clone, Copy, PartialEq, Eq)] 4pub enum NailError { 5 EmptyInput, 6 BuildError(WeightError), 7} 8 9impl From<WeightError> for NailError { 10 fn from(value: WeightError) -> Self { 11 Self::BuildError(value) 12 } 13} 14 15impl core::fmt::Display for NailError { 16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 17 match self { 18 NailError::EmptyInput => write!(f, "Text input is empty"), 19 NailError::BuildError(e) => { 20 write!(f, "Failed to build token weight distributions: {e}") 21 } 22 } 23 } 24} 25 26impl core::error::Error for NailError {}