easy_async_opencl3/error/
mod.rs

1use crate::error::{api_error::ApiError, wrapper_error::WrapperError};
2
3pub mod api_error;
4pub mod wrapper_error;
5
6/// # ClError
7/// 
8/// The main error type for this library.
9/// 
10/// Errors can come from two sources:
11/// - `Api`: Errors from the underlying OpenCL API (e.g., invalid arguments, out of memory)
12/// - `Wrapper`: Errors from this library's wrapper code (e.g., failed conversions, missing resources)
13/// 
14/// Both variants implement `Display` and `Error` for easy error handling.
15#[derive(Debug)]
16pub enum ClError {
17    Api(ApiError),
18    Wrapper(WrapperError)
19}
20
21impl std::fmt::Display for ClError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            ClError::Api(err) => write!(f, "OpenCL API Error: {}", err),
25            ClError::Wrapper(err) => write!(f, "Library Wrapper Error: {:?}", err),
26        }
27    }
28}
29
30impl std::error::Error for ClError {
31    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
32        match self {
33            ClError::Api(err) => Some(err),
34            ClError::Wrapper(_) => None, // WrapperError should also implement Error if needed
35        }
36    }
37}