2026-01-08 14:00:01 +01:00
|
|
|
use std::any::Any;
|
|
|
|
|
use std::result;
|
2024-11-29 21:06:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-08 14:00:01 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum ZoodexError {
|
|
|
|
|
CollectionFileReadError,
|
2024-11-29 21:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-08 14:00:01 +01:00
|
|
|
pub type Result<Success> = result::Result<Success, ZoodexError>;
|
2024-11-29 21:06:14 +01:00
|
|
|
|
2026-01-08 14:00:01 +01:00
|
|
|
impl From<Box<dyn Any + Send>> for ZoodexError {
|
|
|
|
|
fn from(error: Box<dyn Any + Send>) -> Self {
|
|
|
|
|
*error.downcast().unwrap()
|
|
|
|
|
}
|
2024-11-29 21:06:14 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-08 14:00:01 +01:00
|
|
|
macro_rules! async_result_context {(
|
|
|
|
|
$future: expr
|
|
|
|
|
$(, ok => $on_success: expr)?
|
|
|
|
|
$(, err => $on_failure: expr)?$(,)?
|
2025-02-12 11:34:38 +01:00
|
|
|
) => {
|
2026-01-08 14:00:01 +01:00
|
|
|
#[allow(unreachable_patterns)]
|
|
|
|
|
match $future.await {
|
|
|
|
|
$(Ok(value) => $on_success(value),)?
|
|
|
|
|
Ok(_) => {},
|
|
|
|
|
$(Err(error) => $on_failure(error),)?
|
|
|
|
|
Err(_) => {},
|
|
|
|
|
}
|
|
|
|
|
}}
|
2024-11-30 16:00:44 +01:00
|
|
|
|
2025-02-12 11:34:38 +01:00
|
|
|
|
|
|
|
|
|
2026-01-08 14:00:01 +01:00
|
|
|
pub(crate) use async_result_context;
|