use std::fmt;
use std::io;
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
CudaNotCompiled,
NoDevice,
InvalidUtf8,
Unbalanced,
InputTooLarge {
len: usize,
max: usize,
},
EmptyInput,
NotSingleValue,
Cuda {
code: i32,
message: String,
},
Internal,
Io(io::Error),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::CudaNotCompiled => write!(f, "cujson was built without the `cuda` feature"),
Error::NoDevice => write!(
f,
"no CUDA device visible (driver responded, device count is 0)"
),
Error::InvalidUtf8 => write!(f, "input is not valid UTF-8"),
Error::Unbalanced => write!(f, "unbalanced JSON structure"),
Error::InputTooLarge { len, max } => {
write!(f, "input is {len} bytes, cuJSON's limit is {max} bytes")
}
Error::EmptyInput => write!(f, "empty input"),
Error::NotSingleValue => write!(f, "{}", crate::tape::NOT_SINGLE_VALUE),
Error::Cuda { code, message } => write!(f, "CUDA error {code}: {message}"),
Error::Internal => write!(f, "internal error"),
Error::Io(e) => write!(f, "I/O error: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}