Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring in "Hardware interrupts" chapter #1140

Open
curryrasul opened this issue Sep 16, 2022 · 3 comments
Open

Small refactoring in "Hardware interrupts" chapter #1140

curryrasul opened this issue Sep 16, 2022 · 3 comments

Comments

@curryrasul
Copy link

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.

@bjorn3
Copy link
Contributor

bjorn3 commented Sep 16, 2022

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

@curryrasul
Copy link
Author

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

@JohnDowson
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants