siraph 0.1.2

A node-based digital signal processing crate
Documentation
use crate::graph::NodeHandle;
use crate::node::Name;

use std::any::TypeId;
use std::fmt;

/// A generic error type for the crate.
#[derive(Clone, Debug)]
pub enum Error {
    /// A node handle was invalid.
    InvalidNodeHandle(NodeHandle),

    /// An input's name was not valid.
    UnknownInput(Name),

    /// An output's name was not valid.
    UnknownOutput(Name),

    /// An input and an output had incompatible types.
    Incompatible { input: TypeId, output: TypeId },

    /// A node depends on itself.
    Cycle(NodeHandle),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Self::InvalidNodeHandle(handle) => {
                write!(f, "The node handle ({}) is invalid", handle.0)
            }
            Self::UnknownInput(name) => write!(f, "The input {} does not exist", name),
            Self::UnknownOutput(name) => write!(f, "The output {} does not exist", name),
            Self::Incompatible { .. } => write!(f, "The input and the output are not compatible"),
            Self::Cycle(handle) => write!(f, "The node ({}) depends on itself", handle.0),
        }
    }
}

/// The result type for the crate.
pub type Result<T> = std::result::Result<T, Error>;