1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright (c) 2022-2023, Radu Racariu.
use uuid::Uuid;
use super::{Link, LinkState};
/// Base Link that uses an abstract
/// optional transmitter type `Tx`.
///
/// Links connect a block output to another block's input.
/// Or, a block input to another block's input.
/// A block output can have multiple links to multiple block inputs.
/// A block input can have multiple links to multiple block inputs.
#[derive(Debug, Default, Clone, PartialEq)]
pub struct BaseLink<Tx> {
/// Unique link id
pub id: Uuid,
/// The target block id
pub target_block_id: Uuid,
/// The target input name
pub target_input: String,
/// Optional transmitter type
pub tx: Option<Tx>,
/// The current link state
pub state: LinkState,
}
impl<Tx: Clone> Link for BaseLink<Tx> {
fn id(&self) -> &Uuid {
&self.id
}
fn target_block_id(&self) -> &Uuid {
&self.target_block_id
}
fn target_input(&self) -> &str {
&self.target_input
}
fn state(&self) -> LinkState {
self.state
}
}
impl<Tx> BaseLink<Tx> {
pub fn new(target_block_id: Uuid, target_input: String) -> Self {
Self {
id: Uuid::new_v4(),
target_block_id,
target_input,
tx: None,
state: LinkState::Disconnected,
}
}
}