@@ -39,9 +39,9 @@ pub fn parse<'a, T: Deserialize<'a> + Clone>(msg: &'a Message) -> Result<T> {
39
39
Ok ( serde_json:: from_slice :: < T > ( msg. payload ( ) ) ?)
40
40
}
41
41
42
- type SwitchDataMapper = fn ( data : & SwitchData ) -> Option < WriteType > ;
42
+ type WriteTypeMapper < T > = fn ( & T ) -> Option < WriteType > ;
43
43
44
- const SWITCH_FIELDS : & [ ( & str , SwitchDataMapper , & str ) ] = & [
44
+ const SWITCH_FIELDS : & [ ( & str , WriteTypeMapper < SwitchData > , & str ) ] = & [
45
45
(
46
46
"output" ,
47
47
|data : & SwitchData | Some ( WriteType :: Int ( data. output as i32 ) ) ,
@@ -74,8 +74,7 @@ const SWITCH_FIELDS: &[(&str, SwitchDataMapper, &str)] = &[
74
74
) ,
75
75
] ;
76
76
77
- type CoverDataMapper = fn ( data : & CoverData ) -> Option < WriteType > ;
78
- const COVER_FIELDS : & [ ( & str , CoverDataMapper , & str ) ] = & [
77
+ const COVER_FIELDS : & [ ( & str , WriteTypeMapper < CoverData > , & str ) ] = & [
79
78
(
80
79
"position" ,
81
80
|data : & CoverData | data. position . map ( WriteType :: Int ) ,
@@ -127,7 +126,7 @@ impl CheckMessage for ShellyLogger {
127
126
fn handle_message < ' a , T : Deserialize < ' a > + Clone + Debug + Timestamped + Typenamed > (
128
127
msg : & ' a Message ,
129
128
txs : & Vec < SyncSender < WriteQuery > > ,
130
- fields : & [ ( & str , fn ( & T ) -> Option < WriteType > , & str ) ] ,
129
+ fields : & [ ( & str , WriteTypeMapper < T > , & str ) ] ,
131
130
) {
132
131
let location = msg. topic ( ) . split ( "/" ) . nth ( 1 ) . unwrap ( ) ;
133
132
let channel = msg. topic ( ) . split ( ":" ) . last ( ) . unwrap ( ) ;
0 commit comments