@@ -15,7 +15,7 @@ use target::Target;
1515#[ cfg( feature = "local-run" ) ]
1616
1717#[ cfg( feature = "local-run" ) ]
18- #[ derive( Debug , RustcEncodable ) ]
18+ #[ derive( Debug , Serialize ) ]
1919pub struct Telemetry {
2020 pub cpu : Cpu ,
2121 pub fs : Vec < FsMount > ,
@@ -55,70 +55,14 @@ impl Telemetry {
5555 pub fn init ( host : & mut Host ) -> Result < Value > {
5656 Ok ( try!( Target :: telemetry_init ( host) ) )
5757 }
58-
59- // XXX While Macros 1.1 are unstable, we can't use Serde to
60- // convert Telemetry => Value, so we have to roll our own.
61- // (https://github.com/rust-lang/rust/issues/35900)
62- #[ cfg( feature = "local-run" ) ]
63- pub fn into_value ( self ) -> Value {
64- let mut cpu: Map < String , Value > = Map :: new ( ) ;
65- cpu. insert ( "vendor" . into ( ) , json ! ( self . cpu. vendor) ) ;
66- cpu. insert ( "brand_string" . into ( ) , json ! ( self . cpu. brand_string) ) ;
67- cpu. insert ( "cores" . into ( ) , json ! ( self . cpu. cores) ) ;
68-
69- let mut fs = Vec :: new ( ) ;
70- for mount in self . fs {
71- let mut map: Map < String , Value > = Map :: new ( ) ;
72- map. insert ( "filesystem" . into ( ) , json ! ( mount. filesystem) ) ;
73- map. insert ( "mountpoint" . into ( ) , json ! ( mount. mountpoint) ) ;
74- map. insert ( "size" . into ( ) , json ! ( mount. size) ) ;
75- map. insert ( "used" . into ( ) , json ! ( mount. used) ) ;
76- map. insert ( "available" . into ( ) , json ! ( mount. available) ) ;
77- map. insert ( "capacity" . into ( ) , json ! ( mount. capacity) ) ;
78- fs. push ( map) ;
79- }
80-
81- let mut net = Vec :: new ( ) ;
82- for netif in self . net {
83- let mut map: Map < String , Value > = Map :: new ( ) ;
84- map. insert ( "name" . into ( ) , json ! ( netif. name) ) ;
85- map. insert ( "index" . into ( ) , json ! ( netif. index) ) ;
86- if let Some ( mac) = netif. mac {
87- map. insert ( "mac" . into ( ) , json ! ( mac) ) ;
88- }
89- if let Some ( ips) = netif. ips {
90- map. insert ( "ips" . into ( ) , json ! ( ips) ) ;
91- }
92- map. insert ( "flags" . into ( ) , json ! ( netif. flags) ) ;
93- net. push ( map) ;
94- }
95-
96- let mut os: Map < String , Value > = Map :: new ( ) ;
97- os. insert ( "arch" . into ( ) , json ! ( self . os. arch) ) ;
98- os. insert ( "family" . into ( ) , json ! ( self . os. family) ) ;
99- os. insert ( "platform" . into ( ) , json ! ( self . os. platform) ) ;
100- os. insert ( "version_str" . into ( ) , json ! ( self . os. version_str) ) ;
101- os. insert ( "version_maj" . into ( ) , json ! ( self . os. version_maj) ) ;
102- os. insert ( "version_min" . into ( ) , json ! ( self . os. version_min) ) ;
103- os. insert ( "version_patch" . into ( ) , json ! ( self . os. version_patch) ) ;
104-
105- let mut telemetry: Map < String , Value > = Map :: new ( ) ;
106- telemetry. insert ( "cpu" . into ( ) , json ! ( cpu) ) ;
107- telemetry. insert ( "fs" . into ( ) , json ! ( fs) ) ;
108- telemetry. insert ( "hostname" . into ( ) , json ! ( self . hostname) ) ;
109- telemetry. insert ( "memory" . into ( ) , json ! ( self . memory) ) ;
110- telemetry. insert ( "net" . into ( ) , json ! ( net) ) ;
111- telemetry. insert ( "os" . into ( ) , json ! ( os) ) ;
112- json ! ( telemetry)
113- }
11458}
11559
11660pub trait TelemetryTarget {
11761 fn telemetry_init ( host : & mut Host ) -> Result < Value > ;
11862}
11963
12064#[ cfg( feature = "local-run" ) ]
121- #[ derive( Debug , RustcEncodable ) ]
65+ #[ derive( Debug , Serialize ) ]
12266pub struct Cpu {
12367 pub vendor : String ,
12468 pub brand_string : String ,
@@ -137,7 +81,7 @@ impl Cpu {
13781}
13882
13983#[ cfg( feature = "local-run" ) ]
140- #[ derive( Debug , RustcEncodable ) ]
84+ #[ derive( Debug , Serialize ) ]
14185pub struct FsMount {
14286 pub filesystem : String ,
14387 pub mountpoint : String ,
@@ -148,7 +92,7 @@ pub struct FsMount {
14892}
14993
15094#[ cfg( feature = "local-run" ) ]
151- #[ derive( Debug , RustcEncodable ) ]
95+ #[ derive( Debug , Serialize ) ]
15296pub struct Netif {
15397 pub name : String ,
15498 pub index : u32 ,
@@ -158,7 +102,7 @@ pub struct Netif {
158102}
159103
160104#[ cfg( feature = "local-run" ) ]
161- #[ derive( Debug , RustcEncodable ) ]
105+ #[ derive( Debug , Serialize ) ]
162106pub struct Os {
163107 pub arch : String ,
164108 pub family : String ,
0 commit comments