Rust: Byte-rearranging methods on `u8` and `i8` should be deprecated

Created on 20 Sep 2017  路  4Comments  路  Source: rust-lang/rust

Considering how there's no common trait for these, it makes sense that u8::swap_bytes, u8::from_le, u8::from_be, u8::to_be, and u8::from_be should all be deprecated. These methods have no effect and it is slightly confusing to have them.

C-feature-request T-libs

Most helpful comment

I think consistency with other integer types can be an argument for keeping the functions even though they are no-ops. Responding to the "there is no trait" argument, you can implement generic stuff via macros as well and expect the functions to exist. Being generic over integer types is notoriously hard as there is no "summary trait" for integers, at least not in the standard library.

All 4 comments

I am slightly confused about this issue, but it might just be me!

  • Why does "there's no common trait for these" matter?
  • They "have no effect"? At least the docs show examples where they do things.

@steveklabnik All of these are identity functions ("no effect") since u8 and i8 are one-byte long.

I think consistency with other integer types can be an argument for keeping the functions even though they are no-ops. Responding to the "there is no trait" argument, you can implement generic stuff via macros as well and expect the functions to exist. Being generic over integer types is notoriously hard as there is no "summary trait" for integers, at least not in the standard library.

As mentioned, these methods can be useful in macro-generated code.

Was this page helpful?
0 / 5 - 0 ratings