From ed3fdcd5e3320558bab856627d27a0ae28f1e344 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Wed, 4 Aug 2021 21:43:53 -0400 Subject: [PATCH] Release 0.6.4, fix unaligned test buffers --- README.md | 38 ++++++--- bytecheck/Cargo.toml | 4 +- bytecheck/README.md | 42 +++++---- bytecheck/crates-io.md | 36 +++++--- bytecheck/src/lib.rs | 35 +++++--- bytecheck_derive/Cargo.toml | 2 +- bytecheck_test/Cargo.toml | 2 +- bytecheck_test/src/lib.rs | 164 +++++++++++++++++------------------- 8 files changed, 178 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index c4f4a7a..3c27121 100644 --- a/README.md +++ b/README.md @@ -21,58 +21,70 @@ struct Test { c: char, } +#[repr(C, align(16))] +struct Aligned([u8; N]); + +macro_rules! bytes { + ($($byte:literal,)*) => { + (&Aligned([$($byte,)*]).0 as &[u8]).as_ptr() + }; + ($($byte:literal),*) => { + bytes!($($byte,)*) + }; +} + fn main() { // This type is laid out as (u32, char, bool) unsafe { // These are valid bytes for (0, 'x', true) Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Changing the bytes for the u32 is OK, any bytes are a valid u32 Test::check_bytes( - &[ + bytes![ 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Characters outside the valid ranges are invalid Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); // 0 is a valid boolean value (false) but 2 is not Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); } } -``` \ No newline at end of file +``` diff --git a/bytecheck/Cargo.toml b/bytecheck/Cargo.toml index c210088..c6fb185 100644 --- a/bytecheck/Cargo.toml +++ b/bytecheck/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytecheck" -version = "0.6.3" +version = "0.6.4" authors = ["David Koloski "] edition = "2018" description = "Derive macro for bytecheck" @@ -14,7 +14,7 @@ readme = "crates-io.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bytecheck_derive = { version = "=0.6.3", path = "../bytecheck_derive", default-features = false } +bytecheck_derive = { version = "=0.6.4", path = "../bytecheck_derive", default-features = false } ptr_meta = "0.1" simdutf8 = { version = "0.1", default-features = false, optional = true } diff --git a/bytecheck/README.md b/bytecheck/README.md index 54660a5..3c27121 100644 --- a/bytecheck/README.md +++ b/bytecheck/README.md @@ -1,11 +1,11 @@ -# bytecheck   [![Latest Version]][crates.io] [![License]][license path] [![requires: rustc 1.47+]][Rust 1.47] +# bytecheck   [![Latest Version]][crates.io] [![License]][license path] [![requires: rustc 1.52+]][Rust 1.52] [Latest Version]: https://img.shields.io/crates/v/bytecheck.svg [crates.io]: https://crates.io/crates/bytecheck [License]: https://img.shields.io/badge/license-MIT-blue.svg [license path]: https://github.com/djkoloski/bytecheck/blob/master/LICENSE -[requires: rustc 1.47+]: https://img.shields.io/badge/rustc-1.47+-lightgray.svg -[Rust 1.47]: https://blog.rust-lang.org/2020/10/08/Rust-1.47.html +[requires: rustc 1.52+]: https://img.shields.io/badge/rustc-1.52+-lightgray.svg +[Rust 1.52]: https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html bytecheck is a type validation framework for Rust. @@ -21,56 +21,68 @@ struct Test { c: char, } +#[repr(C, align(16))] +struct Aligned([u8; N]); + +macro_rules! bytes { + ($($byte:literal,)*) => { + (&Aligned([$($byte,)*]).0 as &[u8]).as_ptr() + }; + ($($byte:literal),*) => { + bytes!($($byte,)*) + }; +} + fn main() { // This type is laid out as (u32, char, bool) unsafe { // These are valid bytes for (0, 'x', true) Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Changing the bytes for the u32 is OK, any bytes are a valid u32 Test::check_bytes( - &[ + bytes![ 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Characters outside the valid ranges are invalid Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); // 0 is a valid boolean value (false) but 2 is not Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); } diff --git a/bytecheck/crates-io.md b/bytecheck/crates-io.md index a8094d9..3aabd87 100644 --- a/bytecheck/crates-io.md +++ b/bytecheck/crates-io.md @@ -12,56 +12,68 @@ struct Test { c: char, } +#[repr(C, align(16))] +struct Aligned([u8; N]); + +macro_rules! bytes { + ($($byte:literal,)*) => { + (&Aligned([$($byte,)*]).0 as &[u8]).as_ptr() + }; + ($($byte:literal),*) => { + bytes!($($byte,)*) + }; +} + fn main() { // This type is laid out as (u32, char, bool) unsafe { // These are valid bytes for (0, 'x', true) Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Changing the bytes for the u32 is OK, any bytes are a valid u32 Test::check_bytes( - &[ + bytes![ 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); // Characters outside the valid ranges are invalid Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); // 0 is a valid boolean value (false) but 2 is not Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap(); Test::check_bytes( - &[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 - ] as *const u8, + ].cast(), &() ).unwrap_err(); } diff --git a/bytecheck/src/lib.rs b/bytecheck/src/lib.rs index 3418217..ddf7d92 100644 --- a/bytecheck/src/lib.rs +++ b/bytecheck/src/lib.rs @@ -29,56 +29,67 @@ //! b: bool, //! c: char, //! } +//! #[repr(C, align(16))] +//! struct Aligned([u8; N]); +//! +//! macro_rules! bytes { +//! ($($byte:literal,)*) => { +//! (&Aligned([$($byte,)*]).0 as &[u8]).as_ptr() +//! }; +//! ($($byte:literal),*) => { +//! bytes!($($byte,)*) +//! }; +//! } //! //! // This type is laid out as (u32, char, bool) //! unsafe { //! // These are valid bytes for (0, 'x', true) //! Test::check_bytes( -//! (&[ +//! bytes![ //! 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, //! 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap(); //! //! // Changing the bytes for the u32 is OK, any bytes are a valid u32 //! Test::check_bytes( -//! (&[ +//! bytes![ //! 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, //! 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap(); //! //! // Characters outside the valid ranges are invalid //! Test::check_bytes( -//! (&[ +//! bytes![ //! 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, //! 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap_err(); //! Test::check_bytes( -//! (&[ +//! bytes![ //! 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, //! 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap_err(); //! //! // 0 is a valid boolean value (false) but 2 is not //! Test::check_bytes( -//! (&[ +//! bytes![ //! 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, //! 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap(); //! Test::check_bytes( -//! (&[ +//! bytes![ //! 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, //! 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8 -//! ] as *const u8).cast(), +//! ].cast(), //! &mut () //! ).unwrap_err(); //! } diff --git a/bytecheck_derive/Cargo.toml b/bytecheck_derive/Cargo.toml index 9f29197..e7345e5 100644 --- a/bytecheck_derive/Cargo.toml +++ b/bytecheck_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytecheck_derive" -version = "0.6.3" +version = "0.6.4" authors = ["David Koloski "] edition = "2018" description = "Derive macro for bytecheck" diff --git a/bytecheck_test/Cargo.toml b/bytecheck_test/Cargo.toml index 828a50a..44b4dae 100644 --- a/bytecheck_test/Cargo.toml +++ b/bytecheck_test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bytecheck_test" -version = "0.6.1" +version = "0.6.4" authors = ["David Koloski "] edition = "2018" description = "Test suite for bytecheck crates" diff --git a/bytecheck_test/src/lib.rs b/bytecheck_test/src/lib.rs index ff10c55..595ff58 100644 --- a/bytecheck_test/src/lib.rs +++ b/bytecheck_test/src/lib.rs @@ -11,6 +11,18 @@ mod tests { unsafe { T::check_bytes(value as *const T, &mut context).unwrap() }; } + #[repr(C, align(16))] + struct Aligned([u8; N]); + + macro_rules! bytes { + ($($byte:literal,)*) => { + (&Aligned([$($byte,)*]).0 as &[u8]).as_ptr() + }; + ($($byte:literal),*) => { + bytes!($($byte,)*) + }; + } + #[test] fn test_tuples() { check_as_bytes(&(42u32, true, 'x'), &mut ()); @@ -19,56 +31,50 @@ mod tests { unsafe { // These tests assume the tuple is packed (u32, bool, char) <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 0x78u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 42u8, 16u8, 20u8, 3u8, 1u8, 255u8, 255u8, 255u8, 0x78u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 0x00u8, 0xd8u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 0x78u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); <(u32, bool, char)>::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 0x78u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); @@ -81,15 +87,11 @@ mod tests { check_as_bytes(&[false, true], &mut ()); unsafe { - <[bool; 4]>::check_bytes((&[1u8, 0u8, 1u8, 0u8] as *const u8).cast(), &mut ()).unwrap(); - <[bool; 4]>::check_bytes((&[1u8, 2u8, 1u8, 0u8] as *const u8).cast(), &mut ()) - .unwrap_err(); - <[bool; 4]>::check_bytes((&[2u8, 0u8, 1u8, 0u8] as *const u8).cast(), &mut ()) - .unwrap_err(); - <[bool; 4]>::check_bytes((&[1u8, 0u8, 1u8, 2u8] as *const u8).cast(), &mut ()) - .unwrap_err(); - <[bool; 4]>::check_bytes((&[1u8, 0u8, 1u8, 0u8, 2u8] as *const u8).cast(), &mut ()) - .unwrap(); + <[bool; 4]>::check_bytes(bytes![1u8, 0u8, 1u8, 0u8].cast(), &mut ()).unwrap(); + <[bool; 4]>::check_bytes(bytes![1u8, 2u8, 1u8, 0u8].cast(), &mut ()).unwrap_err(); + <[bool; 4]>::check_bytes(bytes![2u8, 0u8, 1u8, 0u8].cast(), &mut ()).unwrap_err(); + <[bool; 4]>::check_bytes(bytes![1u8, 0u8, 1u8, 2u8].cast(), &mut ()).unwrap_err(); + <[bool; 4]>::check_bytes(bytes![1u8, 0u8, 1u8, 0u8, 2u8].cast(), &mut ()).unwrap(); } } @@ -113,56 +115,50 @@ mod tests { unsafe { // These tests assume the struct is packed (u32, char, bool) Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); @@ -189,56 +185,50 @@ mod tests { unsafe { // These tests assume the struct is packed (u32, char, bool) Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 42u8, 16u8, 20u8, 3u8, 0x78u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0xd8u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x00u8, 0x00u8, 0x11u8, 0u8, 1u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 0x78u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); @@ -259,22 +249,22 @@ mod tests { unsafe { Test::::check_bytes( - (&[0u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8] as *const u8).cast(), + bytes![0u8, 0u8, 0u8, 0u8, 1u8, 255u8, 255u8, 255u8].cast(), &mut (), ) .unwrap(); Test::::check_bytes( - (&[12u8, 34u8, 56u8, 78u8, 1u8, 255u8, 255u8, 255u8] as *const u8).cast(), + bytes![12u8, 34u8, 56u8, 78u8, 1u8, 255u8, 255u8, 255u8].cast(), &mut (), ) .unwrap(); Test::::check_bytes( - (&[0u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8] as *const u8).cast(), + bytes![0u8, 0u8, 0u8, 0u8, 0u8, 255u8, 255u8, 255u8].cast(), &mut (), ) .unwrap(); Test::::check_bytes( - (&[0u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8] as *const u8).cast(), + bytes![0u8, 0u8, 0u8, 0u8, 2u8, 255u8, 255u8, 255u8].cast(), &mut (), ) .unwrap_err(); @@ -314,38 +304,34 @@ mod tests { unsafe { Test::check_bytes( - (&[ + bytes![ 0u8, 0u8, 0u8, 0u8, 12u8, 34u8, 56u8, 78u8, 1u8, 255u8, 255u8, 255u8, 120u8, 0u8, 0u8, 0u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 1u8, 0u8, 0u8, 0u8, 12u8, 34u8, 56u8, 78u8, 1u8, 255u8, 255u8, 255u8, 120u8, 0u8, 0u8, 0u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 2u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 25u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap(); Test::check_bytes( - (&[ + bytes![ 3u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 255u8, 25u8, 255u8, 255u8, 255u8, - ] as *const u8) - .cast(), + ].cast(), &mut (), ) .unwrap_err(); @@ -371,12 +357,12 @@ mod tests { check_as_bytes(&Test::E, &mut ()); unsafe { - Test::check_bytes((&[1u8] as *const u8).cast(), &mut ()).unwrap_err(); - Test::check_bytes((&[99u8] as *const u8).cast(), &mut ()).unwrap_err(); - Test::check_bytes((&[102u8] as *const u8).cast(), &mut ()).unwrap_err(); - Test::check_bytes((&[199u8] as *const u8).cast(), &mut ()).unwrap_err(); - Test::check_bytes((&[202u8] as *const u8).cast(), &mut ()).unwrap_err(); - Test::check_bytes((&[255u8] as *const u8).cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![1u8].cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![99u8].cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![102u8].cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![199u8].cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![202u8].cast(), &mut ()).unwrap_err(); + Test::check_bytes(bytes![255u8].cast(), &mut ()).unwrap_err(); } } @@ -434,12 +420,12 @@ mod tests { unsafe { Test::check_bytes( - (&[42u8, 0u8, 0u8, 0u8] as *const u8).cast(), + bytes![42u8, 0u8, 0u8, 0u8].cast(), &mut TestContext(42), ) .unwrap(); Test::check_bytes( - (&[41u8, 0u8, 0u8, 0u8] as *const u8).cast(), + bytes![41u8, 0u8, 0u8, 0u8].cast(), &mut TestContext(42), ) .unwrap_err(); @@ -451,12 +437,12 @@ mod tests { unsafe { TestContainer::check_bytes( - (&[42u8, 0u8, 0u8, 0u8] as *const u8).cast(), + bytes![42u8, 0u8, 0u8, 0u8].cast(), &mut TestContext(42), ) .unwrap(); TestContainer::check_bytes( - (&[41u8, 0u8, 0u8, 0u8] as *const u8).cast(), + bytes![41u8, 0u8, 0u8, 0u8].cast(), &mut TestContext(42), ) .unwrap_err();