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
use std::io;
use std::io::Write;

use backend::*;
use output_log::*;

pub struct PipeOutput {
	error_handler: Box <Fn (io::Error) + Send>,
}

impl PipeOutput {

	pub fn new (
		error_handler: Box <Fn (io::Error) + Send>,
	) -> PipeOutput {

		PipeOutput {
			error_handler: error_handler,
		}

	}

}

impl Backend for PipeOutput {

	fn update (
		& mut self,
		logs: & [OutputLogInternal],
	) {

		for log in logs {

			if log.state () != OutputLogState::Message {
				break;
			}

			write! (
				io::stderr (),
				"{}\n",
				log.message (),
			).unwrap_or_else (
				|error|

				(self.error_handler) (
					error)

			);

		}

	}

}

// ex: noet ts=4 filetype=rust