protoflow_core/
block_error.rs1use crate::{
4 prelude::{fmt, Box, Result, String, ToString},
5 PortError,
6};
7
8#[cfg(feature = "std")]
9extern crate std;
10
11pub type BlockResult<T = ()> = Result<T, BlockError>;
12
13#[derive(Debug)]
14pub enum BlockError {
15 Terminated,
16 PortError(PortError),
17 Other(String),
18 #[cfg(feature = "std")]
19 Panic(Box<dyn std::any::Any + Send>),
20}
21
22impl fmt::Display for BlockError {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 match self {
25 Self::Terminated => write!(f, "Execution terminated"),
26 Self::PortError(e) => write!(f, "{}", e),
27 Self::Other(message) => write!(f, "{}", message),
28 #[cfg(feature = "std")]
29 Self::Panic(e) => write!(f, "Panic: {:?}", e),
30 }
31 }
32}
33
34#[cfg(feature = "std")]
35impl std::error::Error for BlockError {}
36
37#[cfg(feature = "std")]
38impl From<std::io::Error> for BlockError {
39 fn from(error: std::io::Error) -> Self {
40 Self::Other(error.to_string())
41 }
42}
43
44#[cfg(feature = "std")]
45impl From<Box<dyn std::any::Any + Send>> for BlockError {
46 fn from(error: Box<dyn std::any::Any + Send>) -> Self {
47 Self::Panic(error)
48 }
49}
50
51impl From<PortError> for BlockError {
52 fn from(error: PortError) -> Self {
53 Self::PortError(error)
54 }
55}