blog_os icon indicating copy to clipboard operation
blog_os copied to clipboard

Small refactoring in "Hardware interrupts" chapter

Open curryrasul opened this issue 2 years ago • 3 comments

There is a code https://os.phil-opp.com/hardware-interrupts/#handling-timer-interrupts

Any reason to make this:

impl InterruptIndex {
    fn as_u8(self) -> u8 {
        self as u8
    }

    fn as_usize(self) -> usize {
        usize::from(self.as_u8())
    }
}

and not this:

impl InterruptIndex {
    fn as_usize(self) -> usize {
        usize::from(self as u8)
    }
}

or even not to create as_usize at all, and just use as usize cast directly?

Thanks for attention.

curryrasul avatar Sep 16 '22 13:09 curryrasul

as_u8 is used in various places where we actually need u8. as_usize could still be rewritten to not use as_u8 though.

bjorn3 avatar Sep 16 '22 14:09 bjorn3

Then wouldn't it be better to use as u8 or as usize everywhere and get rid off this impl's ?

curryrasul avatar Sep 16 '22 17:09 curryrasul

I'd consider as u8 to be more noisy than .as_u8().

JohnDowson avatar Jan 13 '23 13:01 JohnDowson