use crate::node::Node;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Link {
pub to_key: String,
pub dialogue: String,
}
impl Link {
pub fn new<T>(to_key: T, dialogue: T) -> Link
where
T: Into<String>,
{
Link {
to_key: to_key.into(),
dialogue: dialogue.into(),
}
}
pub fn link<T>(from: &mut Node, to: &Node, dialogue: T)
where
T: Into<String>,
{
let link = Link {
to_key: to.key.clone(),
dialogue: dialogue.into(),
};
from.links.push(link);
}
}
#[cfg(test)]
#[test]
fn test_link() {
let mut start_node = Node::new("start", "The start node.");
let end_node = Node::new("end", "The end node.");
let link_dialogue = "A simple link.";
Link::link(&mut start_node, &end_node, link_dialogue);
assert_eq!(1, start_node.links.len());
assert_eq!(link_dialogue, start_node.links.first().unwrap().dialogue);
}