Skip to main content

fast_mesh_query/
error.rs

1//! Errors reported by queries.
2
3use std::fmt;
4
5/// Why a query could not run.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum QueryError {
8    /// The BVH was built for a different mesh.
9    MeshMismatch,
10    /// The mesh changed since the BVH was last updated.
11    StaleBvh,
12    /// An argument was invalid (non-finite, negative radius and so on).
13    InvalidInput(&'static str),
14    /// Memory for the result could not be reserved.
15    OutOfMemory,
16}
17
18impl fmt::Display for QueryError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            QueryError::MeshMismatch => f.write_str("the BVH was built for a different mesh"),
22            QueryError::StaleBvh => f.write_str("the BVH is out of date with the mesh"),
23            QueryError::InvalidInput(what) => write!(f, "invalid input: {what}"),
24            QueryError::OutOfMemory => f.write_str("out of memory"),
25        }
26    }
27}
28
29impl std::error::Error for QueryError {}
30
31/// `Result` with [`QueryError`] as the error type.
32pub type Result<T> = std::result::Result<T, QueryError>;