convo/node.rs
1use crate::link::Link;
2
3/// A [`Node`] is a node in a conversation tree. It canonically acts as a fork of decisions by wrapping prompting [`dialogue`][`Node#structfield.dialogue`] and a list of path options (called [`Link`]s).
4#[derive(Debug, Clone, Eq, PartialEq)]
5pub struct Node {
6 /// The key of this node. Must be unique.
7 pub key: String,
8
9 /// The dialogue of this node.
10 pub dialogue: String,
11
12 /// A container of [`Link`]s, which connect to other [`Node`]s.
13 pub links: Vec<Link>,
14}
15
16impl Node {
17 /// Returns a [`Node`] with prompting dialogue. The structure returned contains no links.
18 ///
19 /// # Arguments
20 ///
21 /// * `key` - A string type that holds unique identifier for indexing.
22 /// * `dialogue` - A string type that holds associated descriptor dialogue.
23 ///
24 /// # Examples
25 ///
26 /// ```
27 /// use convo::Node;
28 /// let node = Node::new("start", "How are you?");
29 /// ```
30 pub fn new<T>(key: T, dialogue: T) -> Node
31 where
32 T: Into<String>,
33 {
34 Node {
35 key: key.into(),
36 dialogue: dialogue.into(),
37 links: vec![],
38 }
39 }
40}