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
use std::iter::FromIterator;
use crate::utils;

#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
pub struct Comment(pub Vec<String>);

impl Comment {
    pub fn new(s: &str) -> Self {
        s.lines()
            .filter_map(
                |s| utils::keyword("REM")(s)
                    .ok()
                    .map(|(c, _)| c)
            )
            .collect()
    }
    pub fn push(&mut self, s: String) {
        self.0.push(s)
    }
}
impl<S: Into<String>> FromIterator<S> for Comment {
    fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self {
        Self(iter.into_iter().map(Into::into).collect())
    }
}
impl IntoIterator for Comment {
    type Item = String;
    type IntoIter = <Vec<String> as IntoIterator>::IntoIter;
    
    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}