bytecodealliance / rustix

Safe Rust bindings to POSIX-ish APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misleading name of `ioctl::BadOpcode`

oxalica opened this issue · comments

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.

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.