@@ -287,18 +287,18 @@ impl TryFrom<i8> for Exception {
287
287
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
288
288
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
289
289
#[ cfg_attr( feature = "std" , derive( PartialOrd , Hash ) ) ]
290
- pub enum Vector {
290
+ pub enum Vector < INT = u16 > {
291
291
/// Thread mode
292
292
ThreadMode ,
293
293
294
294
/// Processor core exception (internal interrupts)
295
295
Exception ( Exception ) ,
296
296
297
297
/// Device specific exception (external interrupts)
298
- Interrupt {
298
+ Interrupt (
299
299
/// Interrupt number. This number is always in range `[0, 495]` (9-bit integer - 16)
300
- irqn : u16 ,
301
- } ,
300
+ INT ,
301
+ ) ,
302
302
}
303
303
304
304
impl Vector {
@@ -311,10 +311,20 @@ impl Vector {
311
311
match isrn {
312
312
0 => Self :: ThreadMode ,
313
313
2 ..=15 => Self :: Exception ( Exception :: new_unchecked ( isrn as i8 - 16 ) ) ,
314
- 16 ..=511 => Self :: Interrupt { irqn : isrn - 16 } ,
314
+ 16 ..=511 => Self :: Interrupt ( isrn - 16 ) ,
315
315
_ => core:: hint:: unreachable_unchecked ( ) ,
316
316
}
317
317
}
318
+
319
+ /// Map the interrupt number to a different type.
320
+ #[ inline]
321
+ pub fn map_interrupt < INT > ( & self , f : impl FnOnce ( u16 ) -> INT ) -> Vector < INT > {
322
+ match self {
323
+ Self :: ThreadMode => Vector :: ThreadMode ,
324
+ Self :: Exception ( ex) => Vector :: Exception ( * ex) ,
325
+ Self :: Interrupt ( irqn) => Vector :: Interrupt ( f ( * irqn) ) ,
326
+ }
327
+ }
318
328
}
319
329
320
330
impl TryFrom < u16 > for Vector {
@@ -326,7 +336,7 @@ impl TryFrom<u16> for Vector {
326
336
Ok ( match isrn {
327
337
0 => Self :: ThreadMode ,
328
338
2 ..=15 => Self :: Exception ( Exception :: try_from ( isrn as i8 - 16 ) . or ( Err ( isrn) ) ?) ,
329
- 16 ..=511 => Self :: Interrupt { irqn : isrn - 16 } ,
339
+ 16 ..=511 => Self :: Interrupt ( isrn - 16 ) ,
330
340
_ => return Err ( isrn) ,
331
341
} )
332
342
}
0 commit comments