@@ -3,10 +3,10 @@ use drmem_api::{
33 driver:: { self , DriverConfig } ,
44 Error , Result ,
55} ;
6+ use std:: convert:: Infallible ;
67use std:: future:: Future ;
78use std:: net:: SocketAddrV4 ;
89use std:: sync:: Arc ;
9- use std:: { convert:: Infallible , pin:: Pin } ;
1010use tokio:: {
1111 io:: { self , AsyncReadExt } ,
1212 net:: {
@@ -150,14 +150,6 @@ pub struct Instance {
150150 _tx : OwnedWriteHalf ,
151151}
152152
153- pub struct Devices {
154- d_service : driver:: ReadOnlyDevice < bool > ,
155- d_state : driver:: ReadOnlyDevice < bool > ,
156- d_duty : driver:: ReadOnlyDevice < f64 > ,
157- d_inflow : driver:: ReadOnlyDevice < f64 > ,
158- d_duration : driver:: ReadOnlyDevice < f64 > ,
159- }
160-
161153impl Instance {
162154 pub const NAME : & ' static str = "sump-gpio" ;
163155
@@ -282,14 +274,20 @@ impl Instance {
282274 }
283275}
284276
285- impl driver:: API for Instance {
286- type DeviceSet = Devices ;
277+ pub struct Devices {
278+ d_service : driver:: ReadOnlyDevice < bool > ,
279+ d_state : driver:: ReadOnlyDevice < bool > ,
280+ d_duty : driver:: ReadOnlyDevice < f64 > ,
281+ d_inflow : driver:: ReadOnlyDevice < f64 > ,
282+ d_duration : driver:: ReadOnlyDevice < f64 > ,
283+ }
287284
288- fn register_devices (
289- core : driver:: RequestChan ,
285+ impl driver:: Registrator for Devices {
286+ fn register_devices < ' a > (
287+ core : & ' a mut driver:: RequestChan ,
290288 _: & DriverConfig ,
291289 max_history : Option < usize > ,
292- ) -> Pin < Box < dyn Future < Output = Result < Self :: DeviceSet > > + Send > > {
290+ ) -> impl Future < Output = Result < Self > > + Send + ' a {
293291 let service_name = "service" . parse :: < device:: Base > ( ) . unwrap ( ) ;
294292 let state_name = "state" . parse :: < device:: Base > ( ) . unwrap ( ) ;
295293 let duty_name = "duty" . parse :: < device:: Base > ( ) . unwrap ( ) ;
@@ -322,14 +320,18 @@ impl driver::API for Instance {
322320 } )
323321 } )
324322 }
323+ }
324+
325+ impl driver:: API for Instance {
326+ type HardwareType = Devices ;
325327
326328 fn create_instance (
327329 cfg : & DriverConfig ,
328- ) -> Pin < Box < dyn Future < Output = Result < Box < Self > > > + Send > > {
330+ ) -> impl Future < Output = Result < Box < Self > > > + Send {
329331 let addr = Instance :: get_cfg_address ( cfg) ;
330332 let gpm = Instance :: get_cfg_gpm ( cfg) ;
331333
332- let fut = async move {
334+ async move {
333335 // Validate the configuration.
334336
335337 let addr = addr?;
@@ -348,16 +350,14 @@ impl driver::API for Instance {
348350 rx,
349351 _tx,
350352 } ) )
351- } ;
352-
353- Box :: pin ( fut)
353+ }
354354 }
355355
356356 fn run < ' a > (
357357 & ' a mut self ,
358- devices : Arc < Mutex < Devices > > ,
359- ) -> Pin < Box < dyn Future < Output = Infallible > + Send + ' a > > {
360- let fut = async move {
358+ devices : Arc < Mutex < Self :: HardwareType > > ,
359+ ) -> impl Future < Output = Infallible > + Send + ' a {
360+ async move {
361361 // Record the peer's address in the "cfg" field of the
362362 // span.
363363
@@ -415,9 +415,7 @@ impl driver::API for Instance {
415415 }
416416 }
417417 }
418- } ;
419-
420- Box :: pin ( fut)
418+ }
421419 }
422420}
423421
0 commit comments