pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
#[allow(dead_code)]
pub enum Error {
#[error("invalid UTF-8 sequence at byte {offset}")]
Utf8 { offset: u64 },
#[error("JSON syntax error at byte {offset}: {kind}")]
Syntax { offset: u64, kind: SyntaxErrorKind },
#[error("nesting depth exceeds the limit of {limit} at byte {offset}")]
DepthLimit { offset: u64, limit: u32 },
#[error("trailing content after the top-level JSON value at byte {offset}")]
TrailingContent { offset: u64 },
#[error("input of {len} bytes exceeds the maximum supported size of {max} bytes")]
InputTooLarge { len: u64, max: u64 },
#[error("no Metal GPU device available (MTLCreateSystemDefaultDevice returned nil)")]
NoDevice,
#[error("Metal GPU disabled via METAL_JSON_DISABLE_GPU=1")]
GpuDisabled,
#[error("failed to create a Metal command queue")]
NoCommandQueue,
#[error("failed to load Metal shader library: {message}")]
LibraryLoad { message: String },
#[error("Metal shader compilation failed: {message}")]
ShaderCompile { message: String },
#[error("kernel function `{name}` not found in the Metal shader library")]
KernelNotFound { name: String },
#[error("failed to create compute pipeline for kernel `{name}`: {message}")]
PipelineCreate { name: String, message: String },
#[error("failed to allocate a GPU buffer of {bytes} bytes")]
BufferAlloc { bytes: usize },
#[error("invalid buffer layout for zero-copy wrapping: {message}")]
InvalidBufferLayout { message: String },
#[error("GPU command buffer failed: {message}")]
CommandBuffer { message: String },
#[error(transparent)]
Io(#[from] std::io::Error),
#[cfg(feature = "serde")]
#[error(transparent)]
Deserialize(#[from] crate::serde::DeserializeError),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[allow(dead_code)]
pub enum SyntaxErrorKind {
UnexpectedToken,
UnbalancedBrackets,
InvalidLiteral,
InvalidNumber,
InvalidStringEscape,
UnterminatedString,
ControlCharacterInString,
MissingColon,
MissingComma,
EmptyInput,
}
impl core::fmt::Display for SyntaxErrorKind {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let msg = match self {
Self::UnexpectedToken => "unexpected token",
Self::UnbalancedBrackets => "unbalanced brackets",
Self::InvalidLiteral => "invalid literal",
Self::InvalidNumber => "invalid number",
Self::InvalidStringEscape => "invalid string escape",
Self::UnterminatedString => "unterminated string",
Self::ControlCharacterInString => "unescaped control character in string",
Self::MissingColon => "missing ':' in object member",
Self::MissingComma => "missing ',' between values",
Self::EmptyInput => "empty input",
};
f.write_str(msg)
}
}