@@ -26,7 +26,10 @@ use bitflags::bitflags;
2626use core:: fmt;
2727use core:: marker:: PhantomData ;
2828use core:: ops:: Bound :: { Excluded , Included , Unbounded } ;
29- use core:: ops:: { Deref , Index , IndexMut , RangeBounds } ;
29+ use core:: ops:: {
30+ Bound , Deref , Index , IndexMut , Range , RangeBounds , RangeFrom , RangeFull , RangeInclusive ,
31+ RangeTo , RangeToInclusive ,
32+ } ;
3033use volatile:: Volatile ;
3134
3235use super :: gdt:: SegmentSelector ;
@@ -558,6 +561,48 @@ impl IndexMut<u8> for InterruptDescriptorTable {
558561 }
559562}
560563
564+ macro_rules! impl_index_for_idt {
565+ ( $ty: ty) => {
566+ impl Index <$ty> for InterruptDescriptorTable {
567+ type Output = [ Entry <HandlerFunc >] ;
568+
569+ /// Returns the IDT entry with the specified index.
570+ ///
571+ /// Panics if index is outside the IDT (i.e. greater than 255) or if the entry is an
572+ /// exception that pushes an error code (use the struct fields for accessing these entries).
573+ #[ inline]
574+ fn index( & self , index: $ty) -> & Self :: Output {
575+ self . slice( index)
576+ }
577+ }
578+
579+ impl IndexMut <$ty> for InterruptDescriptorTable {
580+ /// Returns a mutable reference to the IDT entry with the specified index.
581+ ///
582+ /// Panics if the entry is an exception that pushes an error code (use the struct fields for accessing these entries).
583+ #[ inline]
584+ fn index_mut( & mut self , index: $ty) -> & mut Self :: Output {
585+ self . slice_mut( index)
586+ }
587+ }
588+ } ;
589+ }
590+
591+ // this list was stolen from the list of implementors in https://doc.rust-lang.org/core/ops/trait.RangeBounds.html
592+ impl_index_for_idt ! ( ( Bound <& u8 >, Bound <& u8 >) ) ;
593+ impl_index_for_idt ! ( ( Bound <u8 >, Bound <u8 >) ) ;
594+ impl_index_for_idt ! ( Range <& u8 >) ;
595+ impl_index_for_idt ! ( Range <u8 >) ;
596+ impl_index_for_idt ! ( RangeFrom <& u8 >) ;
597+ impl_index_for_idt ! ( RangeFrom <u8 >) ;
598+ impl_index_for_idt ! ( RangeInclusive <& u8 >) ;
599+ impl_index_for_idt ! ( RangeInclusive <u8 >) ;
600+ impl_index_for_idt ! ( RangeTo <u8 >) ;
601+ impl_index_for_idt ! ( RangeTo <& u8 >) ;
602+ impl_index_for_idt ! ( RangeToInclusive <& u8 >) ;
603+ impl_index_for_idt ! ( RangeToInclusive <u8 >) ;
604+ impl_index_for_idt ! ( RangeFull ) ;
605+
561606/// An Interrupt Descriptor Table entry.
562607///
563608/// The generic parameter is some [`InterruptFn`], depending on the interrupt vector.
0 commit comments