gnuplot/
datatype.rs1// Copyright (c) 2013-2014 by SiegeLord
2//
3// All rights reserved. Distributed under LGPL 3.0. For full terms see the file LICENSE.
4
5use std::time::Duration;
6
7pub trait DataType: Clone
8{
9 fn get(&self) -> f64;
10}
11
12macro_rules! impl_data_type {
13 ($T:ty) => {
14 impl<'l> DataType for &'l $T
15 {
16 fn get(&self) -> f64
17 {
18 **self as f64
19 }
20 }
21 };
22}
23
24macro_rules! impl_data_type_ref {
25 ($T:ty) => {
26 impl DataType for $T
27 {
28 fn get(&self) -> f64
29 {
30 *self as f64
31 }
32 }
33 };
34}
35
36impl_data_type!(u8);
37impl_data_type!(u16);
38impl_data_type!(u32);
39impl_data_type!(u64);
40impl_data_type!(usize);
41
42impl_data_type!(i8);
43impl_data_type!(i16);
44impl_data_type!(i32);
45impl_data_type!(i64);
46impl_data_type!(isize);
47
48impl_data_type!(f32);
49impl_data_type!(f64);
50
51impl_data_type_ref!(u8);
52impl_data_type_ref!(u16);
53impl_data_type_ref!(u32);
54impl_data_type_ref!(u64);
55impl_data_type_ref!(usize);
56
57impl_data_type_ref!(i8);
58impl_data_type_ref!(i16);
59impl_data_type_ref!(i32);
60impl_data_type_ref!(i64);
61impl_data_type_ref!(isize);
62
63impl_data_type_ref!(f32);
64impl_data_type_ref!(f64);
65
66impl DataType for Duration
67{
68 fn get(&self) -> f64
69 {
70 // GnuPlot can't handle precision lower than milliseconds.
71 self.as_secs() as f64 + self.subsec_millis() as f64 / 1000.0
72 }
73}
74
75impl<'l> DataType for &'l Duration
76{
77 fn get(&self) -> f64
78 {
79 // GnuPlot can't handle precision lower than milliseconds.
80 self.as_secs() as f64 + self.subsec_millis() as f64 / 1000.0
81 }
82}