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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
use std::collections::HashMap; use std::io; use std::fmt; use { Execute, Fingerprint, Template, Function, BuildError, Build, LittleResult, }; pub struct Compiler; impl Compiler { pub fn new() -> Compiler { trace!("create new compiler"); Compiler } } impl<'a, V: fmt::Debug> Build<'a, V> for Compiler { type Output = Executable; fn build( &'a mut self, id: &str, template: Template<V>, calls: &'a HashMap<&'a str, &'a (Function<V> + 'a)> ) -> LittleResult<Self::Output> { trace!("build Executable for compiler with template {:#?} and calls {:#?}", template, calls.keys().collect::<Vec<_>>()); Ok(Executable { id: id.into() }) } fn load(&'a mut self, id: &str, env: Fingerprint, calls: &'a Vec<&'a (Function<V> + 'a)>) -> LittleResult<Self::Output> { unreachable!("compiler load not implemented"); } } pub struct Executable { id: String, } impl<'a, V: fmt::Debug> Execute<'a, V> for Executable { type Stream = CompilerStream; fn execute(&'a self, data: V) -> Self::Stream { trace!("run Executable with data {:#?}", data); CompilerStream } fn get_id<'r>(&'r self) -> &'r str { &self.id } fn identify_env(&self) -> Fingerprint { Fingerprint::empty() } } pub struct CompilerStream; impl io::Read for CompilerStream { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { Ok(0) } } mod ooo { use std::io; #[allow(non_camel_case_types)] pub struct template_ooo; impl template_ooo { pub fn output<I, O>(input: &mut I, output: &mut O) -> Result<usize, io::Error> where I: io::Read + io::Seek, O: io::Write { Ok(0) } } }