use std::error::Error;
use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub enum PxdctError {
OutOfMemory(usize),
CantCreateUnderlyingFft(String),
InvalidSizeMultiplier(usize, usize),
FftError(String),
ZeroSizedDct,
ScratchBufferIsTooSmall(usize, usize),
}
impl Error for PxdctError {}
impl Display for PxdctError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
PxdctError::CantCreateUnderlyingFft(s) => f.write_str(s),
PxdctError::OutOfMemory(length) => {
f.write_fmt(format_args!("Cannot allocate {length} bytes to vector",))
}
PxdctError::InvalidSizeMultiplier(s0, s1) => f.write_fmt(format_args!(
"Size {s0} is assumed to be multiplier of {s1} to execute many DFT, but it wasn't"
)),
PxdctError::FftError(s) => f.write_fmt(format_args!("Underlying fft error {s}")),
PxdctError::ZeroSizedDct => f.write_str("Zero sized DCT is not allowed"),
PxdctError::ScratchBufferIsTooSmall(a, b) => f.write_fmt(format_args!(
"Scratch is expected to be at least {a} bytes, but was {b}"
)),
}
}
}