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

Misleading name of ioctl::BadOpcode #1022

Open
oxalica opened this issue Feb 23, 2024 · 1 comment
Open

Misleading name of ioctl::BadOpcode #1022

oxalica opened this issue Feb 23, 2024 · 1 comment

Comments

@oxalica
Copy link
Contributor

oxalica commented Feb 23, 2024

This struct is to make RawOpcode in const level to satisfy CompileTimeOpcode bound. It is pretty common (and already used by rustix itself) to plug a generated constants, eg. from linux_raw_sys, into the ioctl::{Getter,Setter,Updater} interface. This practice uses less magic numbers in Rust code and should not be called "bad".

This issue was also mentioned in #861

The name Bad made it seem like something I shouldn't be using, but taking the value by name from linux_raw_sys seems less error prone than looking up these components in a C header file and hard-coding them.

I'm not sure about the alternative names here, but here are some candidates:

  1. LiteralOpcode: but it can accept any const expression, not necessarily literals.
  2. RawCompileTimeOpcode: really long to write.
  3. ConstOpcode: seems like synonym to the trait CompileTimeOpcode.
  4. RawOpcode: name collision with type alias RawOpcode.
@notgull
Copy link
Contributor

notgull commented Feb 23, 2024

The name was taken from nix, which I assumed took it from some Linux kernel documentation. I have a memory of finding this document but I can't seem to find it now when I try to look for it.

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

2 participants