use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
#[derive(Debug)]
pub enum ScaletError {
Allocation(usize),
Generic(String),
FftError(String),
InvalidInputSize(usize, usize),
ZeroBaseSized,
WaveletInvalidSize(usize, usize),
}
impl Display for ScaletError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ScaletError::Allocation(size) => {
f.write_fmt(format_args!("Failed to allocate buffer with size {size}"))
}
ScaletError::Generic(msg) => f.write_str(msg),
ScaletError::FftError(msg) => f.write_str(msg),
ScaletError::InvalidInputSize(expected, got) => f.write_fmt(format_args!(
"Input size expected to be {expected} but is was {got}"
)),
ScaletError::ZeroBaseSized => f.write_str("Zero sized CWT is not supported"),
ScaletError::WaveletInvalidSize(expected, actual) => f.write_fmt(format_args!(
"Wavelet is supposed to return size {expected} but it was {actual}"
)),
}
}
}
impl Error for ScaletError {}
macro_rules! try_vec {
() => {
Vec::new()
};
($elem:expr; $n:expr) => {{
let mut v = Vec::new();
v.try_reserve_exact($n)
.map_err(|_| crate::err::ScaletError::Allocation($n))?;
v.resize($n, $elem);
v
}};
}
pub(crate) use try_vec;