Skip to content

Commit

Permalink
Use to_be_bytes instead of unsafe transmute
Browse files Browse the repository at this point in the history
This was introduced with Rust 1.32 and with 1.44 for const values.
  • Loading branch information
klingtnet committed Apr 23, 2023
1 parent 5f70c5e commit f699dff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/decoder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ fn test_decode_udp_args() {
assert_eq!(BigEndian::read_f64(&d_bytes), d);

let i = 12345678i32;
let i_bytes: [u8; 4] = unsafe { mem::transmute(i.to_be()) };
let i_bytes: [u8; 4] = i.to_be_bytes();

let l = -1234567891011i64;
let h_bytes: [u8; 8] = unsafe { mem::transmute(l.to_be()) };
let h_bytes: [u8; 8] = l.to_be_bytes();

let blob_size: [u8; 4] = unsafe { mem::transmute(6u32.to_be()) };
let blob_size: [u8; 4] = 6u32.to_be_bytes();
let blob: Vec<u8> = vec![1u8, 2u8, 3u8, 4u8, 5u8, 6u8];

let s = "I am an osc test string.";
Expand All @@ -104,7 +104,7 @@ fn test_decode_udp_args() {
let s_bytes: Vec<u8> = encoder::encode_string(s);

let c = '$';
let c_bytes: [u8; 4] = unsafe { mem::transmute((c as u32).to_be()) };
let c_bytes: [u8; 4] = (c as u32).to_be_bytes();

let a = vec![OscType::Int(i), OscType::Float(f), OscType::Int(i)];

Expand Down

0 comments on commit f699dff

Please sign in to comment.