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
use core; use std::convert::From; use std::iter::IntoIterator; #[derive(Debug, PartialEq)] pub enum Node { LShift, RShift, Inc, Dec, PutCh, GetCh, Loop(Block), } #[derive(Debug, PartialEq)] pub struct Block(Vec<Node>); impl Block { pub fn new() -> Block { Block(Vec::new()) } pub fn push(&mut self, node: Node) { self.0.push(node); } } impl Default for Block { fn default() -> Self { Block::new() } } impl From<Vec<Node>> for Block { fn from(nodes: Vec<Node>) -> Self { Block(nodes) } } impl<'a> IntoIterator for &'a Block { type Item = &'a Node; type IntoIter = self::core::slice::Iter<'a, Node>; fn into_iter(self) -> Self::IntoIter { self.0.iter() } }