fast_mesh_fields/
error.rs1use std::fmt;
4
5use fast_mesh_query::QueryError;
6use fast_mesh_store::StoreError;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum FieldsError {
11 InvalidInput(&'static str),
14 OutOfMemory,
16 Store(StoreError),
18 Query(QueryError),
20}
21
22impl fmt::Display for FieldsError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 FieldsError::InvalidInput(what) => write!(f, "invalid input: {what}"),
26 FieldsError::OutOfMemory => f.write_str("out of memory"),
27 FieldsError::Store(e) => write!(f, "store error: {e}"),
28 FieldsError::Query(e) => write!(f, "query error: {e}"),
29 }
30 }
31}
32
33impl std::error::Error for FieldsError {
34 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35 match self {
36 FieldsError::Store(e) => Some(e),
37 FieldsError::Query(e) => Some(e),
38 _ => None,
39 }
40 }
41}
42
43impl From<StoreError> for FieldsError {
44 fn from(e: StoreError) -> Self {
45 match e {
46 StoreError::OutOfMemory => FieldsError::OutOfMemory,
47 e => FieldsError::Store(e),
48 }
49 }
50}
51
52impl From<QueryError> for FieldsError {
53 fn from(e: QueryError) -> Self {
54 match e {
55 QueryError::OutOfMemory => FieldsError::OutOfMemory,
56 e => FieldsError::Query(e),
57 }
58 }
59}
60
61pub type Result<T> = std::result::Result<T, FieldsError>;