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
// Copyright (c) 2013-2014 by SiegeLord
//
// All rights reserved. Distributed under LGPL 3.0. For full terms see the file LICENSE.

use std::time::Duration;

pub trait DataType: Clone
{
	fn get(&self) -> f64;
}

macro_rules! impl_data_type {
	($T:ty) => {
		impl<'l> DataType for &'l $T
		{
			fn get(&self) -> f64
			{
				**self as f64
			}
		}
	};
}

macro_rules! impl_data_type_ref {
	($T:ty) => {
		impl DataType for $T
		{
			fn get(&self) -> f64
			{
				*self as f64
			}
		}
	};
}

impl_data_type!(u8);
impl_data_type!(u16);
impl_data_type!(u32);
impl_data_type!(u64);
impl_data_type!(usize);

impl_data_type!(i8);
impl_data_type!(i16);
impl_data_type!(i32);
impl_data_type!(i64);
impl_data_type!(isize);

impl_data_type!(f32);
impl_data_type!(f64);

impl_data_type_ref!(u8);
impl_data_type_ref!(u16);
impl_data_type_ref!(u32);
impl_data_type_ref!(u64);
impl_data_type_ref!(usize);

impl_data_type_ref!(i8);
impl_data_type_ref!(i16);
impl_data_type_ref!(i32);
impl_data_type_ref!(i64);
impl_data_type_ref!(isize);

impl_data_type_ref!(f32);
impl_data_type_ref!(f64);

impl DataType for Duration
{
	fn get(&self) -> f64
	{
		// GnuPlot can't handle precision lower than milliseconds.
		self.as_secs() as f64 + self.subsec_millis() as f64 / 1000.0
	}
}

impl<'l> DataType for &'l Duration
{
	fn get(&self) -> f64
	{
		// GnuPlot can't handle precision lower than milliseconds.
		self.as_secs() as f64 + self.subsec_millis() as f64 / 1000.0
	}
}