pbrt/shared/src/utils/error.rs

39 lines
1.4 KiB
Rust

//! Errors for the shared crate.
//!
//! `shared` is `#![no_std]` and is compiled for SPIR-V and CUDA, so it must not
//! depend on `anyhow` -- whose default features enable `std`. These variants are
//! `Copy` and allocation-free; the CPU-side caller holds the offending string and
//! the `FileLoc`, so it supplies those when reporting.
use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
UnknownWrapMode,
UnknownFilterFunction,
UnknownColorEncoding,
/// `look_at` received an up vector parallel to the viewing direction.
DegenerateLookAt,
/// A transform matrix could not be inverted (pbrt's `InverseOrDie`).
SingularMatrix,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::UnknownWrapMode => "unknown wrap mode",
Self::UnknownFilterFunction => "unknown filter function",
Self::UnknownColorEncoding => "unknown color encoding",
Self::DegenerateLookAt => {
"LookAt: \"up\" vector and viewing direction are parallel"
}
Self::SingularMatrix => "matrix is not invertible",
})
}
}
// Stable in core since 1.81, and the same trait `std::error::Error` re-exports --
// so `?` and `anyhow::Context` keep working unchanged on the CPU side.
impl core::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;