gantz_core 0.4.1

The core types and traits for gantz, an environment for creative systems.
Documentation
//! A simple [`Edge`] type describing the outlet and inlet of source and
//! destination nodes respectively.

use crate::node;
use gantz_ca::CaHash;
use serde::{Deserialize, Serialize};

/// Describes a connection between two nodes.
#[derive(
    Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Deserialize, Serialize, CaHash,
)]
pub struct Edge {
    /// The output of the node at the source of this edge.
    pub output: node::Output,
    /// The input of the node at the destination of this edge.
    pub input: node::Input,
}

impl Edge {
    /// Create an edge representing a connection from the given node `Output` to
    /// the given node `Input`.
    pub fn new(output: node::Output, input: node::Input) -> Self {
        Edge { output, input }
    }
}

impl<A, B> From<(A, B)> for Edge
where
    A: Into<node::Output>,
    B: Into<node::Input>,
{
    fn from((a, b): (A, B)) -> Self {
        let output = a.into();
        let input = b.into();
        Edge { output, input }
    }
}