From 093832dcb24f69809cb30316f51055a2cb6bb330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 17 Jul 2024 14:09:52 +0200 Subject: [PATCH 1/7] docs: clarify that related crates are alternatives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 55c5078..ca41ecc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,8 @@ //! //! # Related crates //! +//! Several crates provide alternative approaches to byte-order-aware numeric types: +//! //! - [endian-type](https://docs.rs/endian-type) //! - [endian-type-rs](https://docs.rs/endian-type-rs) — Depends on `num`. //! - [endiantype](https://docs.rs/endiantype) From a2ef25db71e7f65a0c51d4e67b86abfc8180da71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 17 Jul 2024 14:31:34 +0200 Subject: [PATCH 2/7] test: fix doctests for 32-bit and 16-bit pointer widths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/lib.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 55c5078..e14ae00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -552,6 +552,27 @@ macro_rules! impl_sum_product { impl_sum_product! { Xe Xe Xe Xe Xe Xe Xe Xe Xe Xe Xe Xe } +#[cfg(target_pointer_width = "16")] +macro_rules! usize_macro { + ($macro:ident) => { + $macro!(u16) + }; +} + +#[cfg(target_pointer_width = "32")] +macro_rules! usize_macro { + ($macro:ident) => { + $macro!(u32) + }; +} + +#[cfg(target_pointer_width = "64")] +macro_rules! usize_macro { + ($macro:ident) => { + $macro!(u64) + }; +} + #[rustfmt::skip] macro_rules! rot { (u8) => { 2 }; @@ -559,7 +580,7 @@ macro_rules! rot { (u32) => { 8 }; (u64) => { 12 }; (u128) => { 16 }; - (usize) => { rot!(u64) }; + (usize) => { usize_macro!(rot) }; (i8) => { rot!(u8) }; (i16) => { rot!(u16) }; (i32) => { rot!(u32) }; @@ -575,7 +596,7 @@ macro_rules! rot_op { (u32) => { "0x10000b3" }; (u64) => { "0xaa00000000006e1" }; (u128) => { "0x13f40000000000000000000000004f76" }; - (usize) => { rot_op!(u64) }; + (usize) => { usize_macro!(rot_op) }; (i8) => { "-0x7e" }; (i16) => { "-0x5ffd" }; (i32) => { rot_op!(u32) }; @@ -591,7 +612,7 @@ macro_rules! rot_result { (u32) => { "0xb301" }; (u64) => { "0x6e10aa" }; (u128) => { "0x4f7613f4" }; - (usize) => { rot_result!(u64) }; + (usize) => { usize_macro!(rot_result) }; (i8) => { rot_result!(u8) }; (i16) => { rot_result!(u16) }; (i32) => { rot_result!(u32) }; @@ -607,7 +628,7 @@ macro_rules! swap_op { (u32) => { "0x12345678" }; (u64) => { "0x1234567890123456" }; (u128) => { "0x12345678901234567890123456789012" }; - (usize) => { swap_op!(u64) }; + (usize) => { usize_macro!(swap_op) }; (i8) => { swap_op!(u8) }; (i16) => { swap_op!(u16) }; (i32) => { swap_op!(u32) }; @@ -623,7 +644,7 @@ macro_rules! swapped { (u32) => { "0x78563412" }; (u64) => { "0x5634129078563412" }; (u128) => { "0x12907856341290785634129078563412" }; - (usize) => { swapped!(u64) }; + (usize) => { usize_macro!(swapped) }; (i8) => { swapped!(u8) }; (i16) => { swapped!(u16) }; (i32) => { swapped!(u32) }; @@ -639,7 +660,7 @@ macro_rules! reversed { (u32) => { "0x1e6a2c48" }; (u64) => { "0x6a2c48091e6a2c48" }; (u128) => { "0x48091e6a2c48091e6a2c48091e6a2c48" }; - (usize) => { reversed!(u64) }; + (usize) => { usize_macro!(reversed) }; (i8) => { reversed!(u8) }; (i16) => { reversed!(u16) }; (i32) => { reversed!(u32) }; @@ -654,7 +675,7 @@ macro_rules! be_bytes { (u32) => { "[0x12, 0x34, 0x56, 0x78]" }; (u64) => { "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" }; (u128) => { "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]" }; - (usize) => { be_bytes!(u64) }; + (usize) => { usize_macro!(be_bytes) }; (i8) => { be_bytes!(u8) }; (i16) => { be_bytes!(u16) }; (i32) => { be_bytes!(u32) }; @@ -669,7 +690,7 @@ macro_rules! le_bytes { (u32) => { "[0x78, 0x56, 0x34, 0x12]" }; (u64) => { "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]" }; (u128) => { "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]" }; - (usize) => { le_bytes!(u64) }; + (usize) => { usize_macro!(le_bytes) }; (i8) => { le_bytes!(u8) }; (i16) => { le_bytes!(u16) }; (i32) => { le_bytes!(u32) }; From f67f48407e6e65bea9d6d7dbe2ca2c25ecefbeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 17 Jul 2024 16:01:16 +0200 Subject: [PATCH 3/7] chore: remove appendix from LICENSE-APACHE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- LICENSE-APACHE | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 16fe87b..1b5ec8b 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -174,28 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. From dadea139fc2fe0dc6d5abf0b00d691bc216a3f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 17 Jul 2024 16:27:13 +0200 Subject: [PATCH 4/7] chore: release version 0.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5087e9f..b0eb7ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "endian-num" -version = "0.1.1" +version = "0.1.2" dependencies = [ "bitflags", "bytemuck", diff --git a/Cargo.toml b/Cargo.toml index c617444..9963f8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "endian-num" -version = "0.1.1" +version = "0.1.2" authors = ["Martin Kröning "] edition = "2021" description = "Byte-order-aware numeric types." From c5ecc4a793da6e08b15f5be3338452f11cba2cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 13 Oct 2024 12:09:19 +0200 Subject: [PATCH 5/7] build(deps): update `Cargo.lock` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` Updating bitflags v2.5.0 -> v2.6.0 Updating bytemuck v1.16.0 -> v1.19.0 Updating bytemuck_derive v1.6.0 -> v1.8.0 Updating proc-macro2 v1.0.83 -> v1.0.87 Updating quote v1.0.36 -> v1.0.37 Updating syn v2.0.65 -> v2.0.79 Updating unicode-ident v1.0.12 -> v1.0.13 Updating zerocopy v0.7.34 -> v0.7.35 (latest: v0.8.5) Updating zerocopy-derive v0.7.34 -> v0.7.35 (latest: v0.8.5) ``` Signed-off-by: Martin Kröning --- Cargo.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0eb7ef..fbc8e83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bytemuck" -version = "1.16.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" +checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" [[package]] name = "bytemuck_derive" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" +checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec" dependencies = [ "proc-macro2", "quote", @@ -38,27 +38,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.83" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] [[package]] name = "syn" -version = "2.0.65" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -67,24 +67,24 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", From e39d2158daadb72d18c92d3d0a9672a12d834a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 13 Oct 2024 12:10:38 +0200 Subject: [PATCH 6/7] feat: upgrade zerocopy to 0.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- src/lib.rs | 17 ++++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbc8e83..6e2a9a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,18 +73,18 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "zerocopy" -version = "0.7.35" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +checksum = "6129d25825e874589a0e529175dd060c13dab4f3d960c6a0b711e5535b598bb2" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.35" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +checksum = "d917df3784b4e2f5deb708d14623b2c02833890e1aa7a5dd1088998e8e9402b1" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 9963f8e..603ec69 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ rustdoc-args = ["--cfg", "docsrs"] bitflags = { version = "2", optional = true } bytemuck = { version = "1", optional = true } bytemuck_derive = { version = "1", optional = true } -zerocopy = { version = "0.7", optional = true, default-features = false } -zerocopy-derive = { version = "0.7", optional = true } +zerocopy = { version = "0.8", optional = true, default-features = false } +zerocopy-derive = { version = "0.8", optional = true } [features] bitflags = ["dep:bitflags"] diff --git a/src/lib.rs b/src/lib.rs index 4a69dec..c25cf5c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ //! - [`bitflags`] — `Be` and `Le` implement [`Bits`], [`ParseHex`], and [`WriteHex`]. //! - [`bytemuck`] — `Be` and `Le` implement [`Zeroable`] and [`Pod`]. //! - `linux-types` — Type aliases like in [`linux/types.h`], such as [`le32`]. -//! - [`zerocopy`] — `Be` and `Le` implement [`FromZeroes`], [`FromBytes`], and [`AsBytes`]. +//! - [`zerocopy`] — `Be` and `Le` implement [`KnownLayout`], [`Immutable`], [`FromBytes`], and [`IntoBytes`]. //! //! [`Bits`]: bitflags::Bits //! [`ParseHex`]: bitflags::parser::ParseHex @@ -62,9 +62,10 @@ //! [`Zeroable`]: bytemuck::Zeroable //! [`Pod`]: bytemuck::Pod //! [`linux/types.h`]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/types.h?h=v6.9#n36 -//! [`FromZeroes`]: zerocopy::FromZeroes +//! [`KnownLayout`]: zerocopy::KnownLayout +//! [`Immutable`]: zerocopy::Immutable //! [`FromBytes`]: zerocopy::FromBytes -//! [`AsBytes`]: zerocopy::AsBytes +//! [`IntoBytes`]: zerocopy::IntoBytes //! //! # Related crates //! @@ -118,9 +119,10 @@ use core::{fmt, mem}; #[cfg_attr( feature = "zerocopy", derive( - zerocopy_derive::FromZeroes, + zerocopy_derive::KnownLayout, + zerocopy_derive::Immutable, zerocopy_derive::FromBytes, - zerocopy_derive::AsBytes + zerocopy_derive::IntoBytes, ) )] #[derive(Default, Hash, PartialEq, Eq, Clone, Copy)] @@ -149,9 +151,10 @@ pub struct Be(pub T); #[cfg_attr( feature = "zerocopy", derive( - zerocopy_derive::FromZeroes, + zerocopy_derive::KnownLayout, + zerocopy_derive::Immutable, zerocopy_derive::FromBytes, - zerocopy_derive::AsBytes + zerocopy_derive::IntoBytes, ) )] #[derive(Default, Hash, PartialEq, Eq, Clone, Copy)] From 611cf1b646cca73334acaafa62fa3b1b2bfbb221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 13 Oct 2024 12:30:26 +0200 Subject: [PATCH 7/7] chore: release version 0.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e2a9a4..b22e108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ [[package]] name = "endian-num" -version = "0.1.2" +version = "0.2.0" dependencies = [ "bitflags", "bytemuck", diff --git a/Cargo.toml b/Cargo.toml index 603ec69..af550ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "endian-num" -version = "0.1.2" +version = "0.2.0" authors = ["Martin Kröning "] edition = "2021" description = "Byte-order-aware numeric types."