@@ -124,14 +124,22 @@ impl<T: Common> RxCaps<T> {
124124 }
125125}
126126
127+ /// Struct for [`RxCapsError::ExpectedPdo`]
128+ #[ derive( Copy , Clone , Debug ) ]
129+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
130+ pub struct InvalidPdoIndex {
131+ pub requested : usize ,
132+ pub max : usize ,
133+ }
134+
127135/// Error type for functions that deal with received capabilities
128136#[ derive( Copy , Clone , Debug ) ]
129137#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
130138pub enum RxCapsError {
131139 /// PDO conversion error
132140 ExpectedPdo ( ExpectedPdo ) ,
133141 /// Invalid PDO index accessed, contains (requested, max)
134- InvalidPdoIndex ( usize , usize ) ,
142+ InvalidPdoIndex ( InvalidPdoIndex ) ,
135143}
136144
137145impl < T : RoleCommon > TryFrom < [ u8 ; LEN ] > for RxCaps < T > {
@@ -154,7 +162,12 @@ impl<T: RoleCommon> TryFrom<[u8; LEN]> for RxCaps<T> {
154162 4 => raw. pdo4 ( ) ,
155163 5 => raw. pdo5 ( ) ,
156164 6 => raw. pdo6 ( ) ,
157- _ => return Err ( RxCapsError :: InvalidPdoIndex ( i, NUM_SPR_PDOS ) ) ,
165+ _ => {
166+ return Err ( RxCapsError :: InvalidPdoIndex ( InvalidPdoIndex {
167+ requested : i,
168+ max : NUM_SPR_PDOS ,
169+ } ) )
170+ }
158171 } )
159172 . map_err ( RxCapsError :: ExpectedPdo ) ?;
160173 }
@@ -171,7 +184,12 @@ impl<T: RoleCommon> TryFrom<[u8; LEN]> for RxCaps<T> {
171184 1 => raw. epr_pdo1 ( ) ,
172185 2 => raw. epr_pdo2 ( ) ,
173186 3 => raw. epr_pdo3 ( ) ,
174- _ => return Err ( RxCapsError :: InvalidPdoIndex ( i, NUM_EPR_PDOS ) ) ,
187+ _ => {
188+ return Err ( RxCapsError :: InvalidPdoIndex ( InvalidPdoIndex {
189+ requested : i,
190+ max : NUM_EPR_PDOS ,
191+ } ) )
192+ }
175193 } )
176194 . map_err ( RxCapsError :: ExpectedPdo ) ?;
177195 }
0 commit comments