mod calc;
mod config;
mod picker;
pub use crate::{config::*, picker::*};
pub fn pick<T>(amount: usize, conf: Config<T>) -> Result<Vec<T>, Error>
where
T: Clone + Eq + std::hash::Hash,
{
Picker::build(conf)?.pick(amount)
}
#[derive(Debug)]
pub enum Error {
InvalidTable,
InvalidAmount,
RandError(rand::Error),
ThreadError,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {
InvalidTable => write!(f, "Invalid probability table"),
InvalidAmount => write!(f, "Invalid amount of items to be picked up"),
RandError(e) => write!(f, "RNG Error: {:?}", e),
ThreadError => write!(f, "Thread error during calculation"),
}
}
}
impl std::error::Error for Error {}