Skip to main content

jellyflow_runtime/runtime/policy/
port.rs

1use crate::io::NodeGraphInteractionState;
2use jellyflow_core::core::{Node, Port};
3
4use super::resolve_node_interaction_policy;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct NodeGraphPortInteractionPolicy {
8    pub connectable: bool,
9    pub connectable_start: bool,
10    pub connectable_end: bool,
11}
12
13impl NodeGraphPortInteractionPolicy {
14    pub fn can_start_connection(self) -> bool {
15        self.connectable_start
16    }
17
18    pub fn can_accept_connection(self) -> bool {
19        self.connectable_end
20    }
21}
22
23pub fn resolve_port_interaction_policy(
24    node: &Node,
25    port: &Port,
26    state: &NodeGraphInteractionState,
27) -> NodeGraphPortInteractionPolicy {
28    let node_policy = resolve_node_interaction_policy(node, state);
29    let connectable = node_policy.connectable && port.connectable.unwrap_or(true);
30    NodeGraphPortInteractionPolicy {
31        connectable,
32        connectable_start: connectable && port.connectable_start.unwrap_or(true),
33        connectable_end: connectable && port.connectable_end.unwrap_or(true),
34    }
35}