pub fn build(&mut self) {
        let mut queue = VecDeque::new();
        let node = self.clone();

        for child in self.children.values_mut() {
            child.fail = Some(Box::new(node.clone()));
            queue.push_back(child);
        }

        while let Some(current) = queue.pop_front() {
            for (char, child) in current.children.iter_mut() {
                let mut fail_node = current.fail.clone().unwrap();
                while !fail_node.children.contains_key(char) && fail_node.fail.is_some() {
                    fail_node = fail_node.fail.clone().unwrap();
                }

                if let Some(fail_child) = fail_node.children.get(char) {
                    child.fail = Some(Box::new(fail_child.clone()));
                    child.keywords.extend(fail_child.keywords.iter().cloned());
                } else {
                    child.fail = Some(fail_node);
                }

                queue.push_back(child);
            }
        }
    }
Build fail pointers for the tree.
autocorrect/src/keyword.rs