struct/
struct.rs

1
2extern crate clucolor;
3
4use clucolor::cluColor;
5use clucolor::colors::BrightRed;
6use std::marker::PhantomData;
7use std::time::SystemTime;
8
9fn main() {
10	
11	let time_start = SystemTime::now();
12	println!("Start time {:?} nanos", time_start.elapsed().unwrap().subsec_nanos());
13	
14	let writer = MyWriter::<BrightRed>::new(time_start);
15	writer.println("OK");
16	writer.println("OK12");
17	writer.println("OK123");
18}
19
20
21#[derive(Debug)]
22pub struct MyWriter<C: cluColor> {
23	_c: PhantomData<C>,
24	time: SystemTime,
25}
26
27impl<C: cluColor> MyWriter<C> {
28	#[inline]
29	pub fn new(time: SystemTime) -> MyWriter<C> {
30		MyWriter {
31			_c: PhantomData,
32			time: time,
33		}
34	}
35	
36	#[inline]
37	pub fn string<'a>(&self, str: &'a str) -> String {
38		C::string_fmt( format_args!("[{:?} nanos] {}", SystemTime::now().elapsed().unwrap().subsec_nanos(), str) )
39	}
40	
41	pub fn println<'a>(&self, str: &'a str) {
42		println!("{}", self.string(str));
43	}
44}
45
46
47