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

use crate::{SgfToken};

/// A game node, containing a vector of tokens 
#[derive(Debug, PartialEq, Clone)]
pub struct GameNode {
    pub tokens: Vec<SgfToken>,
}

impl GameNode {
    /// Gets a vector of all `SgfToken::Unknown` tokens
    pub fn get_unknown_tokens(&self) -> Vec<&SgfToken> {
        self
            .tokens
            .iter()
            .filter(|token| {
                 match token {
                    SgfToken::Unknown(_) => true,
                    _ => false
                 }
            })
            .collect::<Vec<_>>()
    }

    /// Gets a vector of all `SgfToken::Invalid` tokens
    pub fn get_invalid_tokens(&self) -> Vec<&SgfToken> {
        self
            .tokens
            .iter()
            .filter(|token| {
                 match token {
                    SgfToken::Invalid(_) => true,
                    _ => false
                 }
            })
            .collect::<Vec<_>>()
    }
}

impl Into<String> for &GameNode {
    fn into(self) -> String {
        self.tokens.iter().fold(";".to_string(), |out, token| {
            let s: String = token.into();
            format!("{}{}", out, s)
        })
    }
}

impl Into<String> for GameNode {
    fn into(self) -> String {
        (&self).into()
    }
}