siraph/
error.rs

1use crate::graph::NodeHandle;
2use crate::node::Name;
3
4use std::any::TypeId;
5use std::fmt;
6
7/// A generic error type for the crate.
8#[derive(Clone, Debug)]
9pub enum Error {
10    /// A node handle was invalid.
11    InvalidNodeHandle(NodeHandle),
12
13    /// An input's name was not valid.
14    UnknownInput(Name),
15
16    /// An output's name was not valid.
17    UnknownOutput(Name),
18
19    /// An input and an output had incompatible types.
20    Incompatible { input: TypeId, output: TypeId },
21
22    /// A node depends on itself.
23    Cycle(NodeHandle),
24}
25
26impl fmt::Display for Error {
27    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28        match self {
29            Self::InvalidNodeHandle(handle) => {
30                write!(f, "The node handle ({}) is invalid", handle.0)
31            }
32            Self::UnknownInput(name) => write!(f, "The input {} does not exist", name),
33            Self::UnknownOutput(name) => write!(f, "The output {} does not exist", name),
34            Self::Incompatible { .. } => write!(f, "The input and the output are not compatible"),
35            Self::Cycle(handle) => write!(f, "The node ({}) depends on itself", handle.0),
36        }
37    }
38}
39
40/// The result type for the crate.
41pub type Result<T> = std::result::Result<T, Error>;