num-traits icon indicating copy to clipboard operation
num-traits copied to clipboard

convert between integer and byte array

Open flier opened this issue 5 years ago • 3 comments

After Rust 1.32, the function to_<endian>_bytes and from_<endian>_bytes has stabilizations.

flier avatar Feb 28 '19 10:02 flier

Tests seem crashed at src/int.rs - int::PrimInt::unsigned_shr (line 173)

---- src/int.rs - int::PrimInt::unsigned_shr (line 173) stdout ----
error: literal out of range for i64
 --> src/int.rs:176:9
  |
6 | let n = 0xFEDCBA9876543210i64;
  |         ^^^^^^^^^^^^^^^^^^^^^ help: consider using `u64` instead: `0xFEDCBA9876543210u64`
  |
  = note: #[deny(overflowing_literals)] on by default
  = note: the literal `0xFEDCBA9876543210i64` (decimal `18364758544493064720`) does not fit into an `i64` and will become `-81985529216486896i64`
thread 'src/int.rs - int::PrimInt::unsigned_shr (line 173)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:351:13
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

flier avatar Mar 05 '19 06:03 flier

The PR seems to have gone fallow, but if you come back to it, it'd be great to extend this to the float types as they also got these methods in 1.40.

erikbrinkman avatar Mar 02 '21 22:03 erikbrinkman

Hi @erikbrinkman and @cuviper

The PR has be updated

  • The trait has been renamed to ToFromBytes
  • Use autocfg to check the expression
  • Implements ToFromBytes for integer and float

flier avatar Mar 04 '21 04:03 flier

Sorry, I pushed to this branch on accident, but the revived development is in #224.

cuviper avatar Feb 10 '23 22:02 cuviper