diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 32b9037..d3066ad 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -14,16 +14,33 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - name: Build run: cargo build --verbose - name: Run tests run: cargo test --verbose - name: Run Clippy on generated test code - fail on warnings run: cargo clippy -p packed_struct_tests --all-targets -- -D warnings + - name: Check feature combinations + run: | + cargo check -p packed_struct --no-default-features + cargo check -p packed_struct --no-default-features --features alloc + cargo check -p packed_struct --all-features - name: Rust no_std tests run: cd packed_struct_nostd_tests && cargo test --verbose - + + msrv: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + - uses: dtolnay/rust-toolchain@1.85 + - name: Check on MSRV + run: cargo check --workspace --all-targets + build-cross: runs-on: ubuntu-latest needs: [build] @@ -31,13 +48,14 @@ jobs: strategy: fail-fast: false matrix: - target: [aarch64-unknown-linux-gnu, arm-unknown-linux-gnueabihf, mips64-unknown-linux-gnuabi64, riscv64gc-unknown-linux-gnu ] + target: [aarch64-unknown-linux-gnu, arm-unknown-linux-gnueabihf, s390x-unknown-linux-gnu, riscv64gc-unknown-linux-gnu ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 + - uses: dtolnay/rust-toolchain@stable - name: Install rust-embedded/cross run: cargo install cross - name: Cross-build run: cross build --target ${{ matrix.target }} - name: Cross-run tests - run: cross test --target ${{ matrix.target }} \ No newline at end of file + run: cross test --target ${{ matrix.target }} diff --git a/Cargo.toml b/Cargo.toml index b6fc9e7..8693403 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "3" members = [ "packed_struct/", "packed_struct_codegen/", @@ -6,6 +7,26 @@ members = [ "packed_struct_examples/" ] +# Built separately: a workspace-wide build would unify packed_struct_codegen's +# `std` feature (enabled by packed_struct_tests) and emit std paths into this no_std crate. exclude = [ "packed_struct_nostd_tests/" -] \ No newline at end of file +] + +[workspace.package] +version = "0.12.0" +authors = ["Rudi Benkovic "] +edition = "2024" +rust-version = "1.85" +license = "MIT OR Apache-2.0" +repository = "https://github.com/hashmismatch/packed_struct.rs" + +[workspace.dependencies] +packed_struct = { path = "packed_struct/", version = "0.12.0", default-features = false } +packed_struct_codegen = { path = "packed_struct_codegen/", version = "0.12.0" } +syn = { version = "3.0.6", features = ["full"] } +quote = "1.0.47" +proc-macro2 = "1.0.107" +serde = { version = "1.0.229", default-features = false } +bitvec = { version = "1.1.1", default-features = false } +error-chain = "0.12.4" diff --git a/README.md b/README.md index 949ea25..0ca0288 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ provide safe packing, unpacking and runtime debugging formatters with per-field # Crate-level feature flags * `std`: use the Rust standard library. Default. - * `alloc`: use the `alloc` crate for `no_std` + `alloc` scenarios. Requires nightly Rust. + * `alloc`: use the `alloc` crate for `no_std` + `alloc` scenarios. * `use_serde`: add serialization support to the built-in helper types. * `byte_types_64`, `byte_types_256`: enlarge the size of the generated array, byte and bit width types. @@ -35,13 +35,11 @@ provide safe packing, unpacking and runtime debugging formatters with per-field ```toml [dependencies] -packed_struct = "0.10" +packed_struct = "0.12" ``` ## Importing the library with the the most common traits and the derive macros ```rust -// This is only needed for pre Rust 2018 -#[macro_use] extern crate packed_struct; // Prelude import with the common imports use packed_struct::prelude::*; ``` diff --git a/packed_struct/Cargo.toml b/packed_struct/Cargo.toml index b2f0f4d..f43d4f7 100644 --- a/packed_struct/Cargo.toml +++ b/packed_struct/Cargo.toml @@ -1,27 +1,26 @@ [package] name = "packed_struct" description = "Binary-level structure packing and unpacking generator" -repository = "https://github.com/hashmismatch/packed_struct.rs" homepage = "http://www.hashmismatch.net/libraries/packed-struct/" -version = "0.11.0" -rust-version = "1.51" -authors = ["Rudi Benkovic "] -license = "MIT OR Apache-2.0" keywords = ["enum", "packing", "serialization"] categories = ["encoding"] readme = "../README.md" -edition = "2018" +version.workspace = true +authors.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true [dependencies] -packed_struct_codegen = { path = "../packed_struct_codegen/", version = "0.11.0" } -serde = { version = "1.0", optional = true, default-features = false } -serde_derive = { version = "1.0", optional = true } -bitvec = { version = "1.0", default-features = false } +packed_struct_codegen.workspace = true +serde = { workspace = true, optional = true } +bitvec.workspace = true [features] default = ["std"] -std = ["serde/std", "packed_struct_codegen/std"] +std = ["serde?/std", "packed_struct_codegen/std"] alloc = ["packed_struct_codegen/alloc"] byte_types_64 = [] byte_types_256 = [] -use_serde = ["serde", "serde_derive"] \ No newline at end of file +use_serde = ["dep:serde", "serde/derive"] diff --git a/packed_struct/src/internal_prelude/no_std.rs b/packed_struct/src/internal_prelude/no_std.rs index 1977e06..fee109d 100644 --- a/packed_struct/src/internal_prelude/no_std.rs +++ b/packed_struct/src/internal_prelude/no_std.rs @@ -1,8 +1,11 @@ +#![allow(unused_imports)] + pub use core::marker::PhantomData; pub use core::iter; pub use core::cell::RefCell; pub use core::fmt; +pub use core::fmt::Formatter; pub use core::fmt::{Debug, Display}; pub use core::fmt::Write as FmtWrite; pub use core::fmt::Error as FmtError; @@ -10,7 +13,7 @@ pub use core::ops::Range; pub use core::num::Wrapping; pub use core::cmp::*; pub use core::mem; -pub use core::intrinsics::write_bytes; +pub use core::ptr::write_bytes; pub use core::ops::Deref; pub use core::slice; pub use core::hash::{Hash, Hasher}; diff --git a/packed_struct/src/internal_prelude/std.rs b/packed_struct/src/internal_prelude/std.rs index 85f04d6..119a7c7 100644 --- a/packed_struct/src/internal_prelude/std.rs +++ b/packed_struct/src/internal_prelude/std.rs @@ -1,3 +1,5 @@ +#![allow(unused_imports)] + pub use std::prelude::v1::*; pub use std::cell::RefCell; pub use std::rc::Rc; diff --git a/packed_struct/src/lib.rs b/packed_struct/src/lib.rs index 833a200..9f479a7 100644 --- a/packed_struct/src/lib.rs +++ b/packed_struct/src/lib.rs @@ -25,7 +25,7 @@ //! //! # Crate-level feature flags //! * `std`: use the Rust standard library. Default. -//! * `alloc`: use the `alloc` crate for `no_std` + `alloc` scenarios. Requires nightly Rust. +//! * `alloc`: use the `alloc` crate for `no_std` + `alloc` scenarios. //! * `use_serde`: add serialization support to the built-in helper types. //! * `byte_types_64`, `byte_types_256`: enlarge the size of the generated array, byte and bit width types. //! @@ -35,13 +35,11 @@ //! //! ```toml //! [dependencies] -//! packed_struct = "0.10" +//! packed_struct = "0.12" //! ``` //! ## Importing the library with the the most common traits and the derive macros //! //! ```rust -//! // This is only needed for pre Rust 2018 -//! #[macro_use] extern crate packed_struct; //! // Prelude import with the common imports //! use packed_struct::prelude::*; //! # fn main() { @@ -318,19 +316,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(feature="alloc", feature(alloc))] - -extern crate packed_struct_codegen; - #[cfg(feature="alloc")] #[macro_use] extern crate alloc; -#[cfg(feature = "use_serde")] -extern crate serde; -#[cfg(feature = "use_serde")] -#[macro_use] extern crate serde_derive; - mod internal_prelude; #[macro_use] @@ -357,19 +346,13 @@ mod types_vec; /// Implementations and wrappers for various packing types. pub mod types { - pub use super::types_basic::*; - /// Types that specify the exact number of bits a packed integer should occupy. pub mod bits { pub use super::super::types_bits::*; } pub use super::types_num::*; - pub use super::types_array::*; pub use super::types_reserved::*; - pub use super::types_generic::*; - #[cfg(any(feature="alloc", feature="std"))] - pub use super::types_vec::*; } pub use self::packing::*; diff --git a/packed_struct/src/packing.rs b/packed_struct/src/packing.rs index f38ffa6..0993823 100644 --- a/packed_struct/src/packing.rs +++ b/packed_struct/src/packing.rs @@ -43,7 +43,7 @@ pub trait PackedStructSlice where Self: Sized { } } -#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Copy, Clone, PartialEq, Eq)] /// Packing errors that might occur during packing or unpacking pub enum PackingError { diff --git a/packed_struct/src/types_num.rs b/packed_struct/src/types_num.rs index 802b5ab..9427120 100644 --- a/packed_struct/src/types_num.rs +++ b/packed_struct/src/types_num.rs @@ -672,7 +672,7 @@ impl PackedStruct for LsbInteger let bits = BitSlice::<_, Msb0>::try_from_slice_mut(bytes_slice).map_err(|_| PackingError::BitsError)?; let s = l - B::number_of_bits(); let (left, _) = bits.split_at_mut(l - leftover_bits); - left.shift_right(s); + left.shift_end(s); } Ok(bytes) @@ -693,7 +693,7 @@ impl PackedStruct for LsbInteger let bits = BitSlice::<_, Msb0>::try_from_slice_mut(bytes_slice).map_err(|_| PackingError::BitsError)?; let s = l - B::number_of_bits(); let (left, _) = bits.split_at_mut(l - leftover_bits); - left.shift_left(s); + left.shift_start(s); I::from_lsb_bytes(&src_bytes)? } else { diff --git a/packed_struct/src/types_reserved.rs b/packed_struct/src/types_reserved.rs index a47b5a8..d4c4d0f 100644 --- a/packed_struct/src/types_reserved.rs +++ b/packed_struct/src/types_reserved.rs @@ -14,7 +14,7 @@ pub trait ReservedBitValue { fn get_reserved_bit_value_byte() -> u8; } -#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Copy, Clone, PartialEq, Eq, Hash)] pub struct BitOne; impl ReservedBitValue for BitOne { @@ -23,7 +23,7 @@ impl ReservedBitValue for BitOne { } } -#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Copy, Clone, PartialEq, Eq, Hash)] pub struct BitZero; impl ReservedBitValue for BitZero { @@ -33,7 +33,7 @@ impl ReservedBitValue for BitZero { } /// Always packs into the associated bit value. Ignores the input when unpacking. -#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "use_serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Default, Copy, Clone, PartialEq, Eq, Hash)] pub struct ReservedBits { value: V, diff --git a/packed_struct_codegen/Cargo.toml b/packed_struct_codegen/Cargo.toml index dabc4e8..a118613 100644 --- a/packed_struct_codegen/Cargo.toml +++ b/packed_struct_codegen/Cargo.toml @@ -1,16 +1,17 @@ [package] name = "packed_struct_codegen" description = "This crate implements the code generation for the packed_struct library." -repository = "https://github.com/hashmismatch/packed_struct.rs" -version = "0.11.0" -license = "MIT OR Apache-2.0" -authors = ["Rudi Benkovic "] -edition = "2018" +version.workspace = true +authors.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true [dependencies] -quote = "1.0" -syn = { version = "2.0", features = ["full"] } -proc-macro2 = "1.0" +quote.workspace = true +syn.workspace = true +proc-macro2.workspace = true [lib] proc-macro = true diff --git a/packed_struct_codegen/src/common.rs b/packed_struct_codegen/src/common.rs index 8eafb01..4a851bc 100644 --- a/packed_struct_codegen/src/common.rs +++ b/packed_struct_codegen/src/common.rs @@ -1,5 +1,3 @@ -extern crate syn; - #[cfg(feature="std")] pub fn collections_prefix() -> syn::Type { syn::parse_str("::std").unwrap() diff --git a/packed_struct_codegen/src/lib.rs b/packed_struct_codegen/src/lib.rs index 0eece96..d9377d5 100644 --- a/packed_struct_codegen/src/lib.rs +++ b/packed_struct_codegen/src/lib.rs @@ -1,13 +1,6 @@ #![recursion_limit = "192"] #![allow(clippy::redundant_clone)] -extern crate proc_macro; -extern crate proc_macro2; - -extern crate syn; -#[macro_use] -extern crate quote; - use proc_macro::TokenStream; use syn::{DeriveInput, parse_macro_input}; diff --git a/packed_struct_codegen/src/pack.rs b/packed_struct_codegen/src/pack.rs index 2129b56..27fa261 100644 --- a/packed_struct_codegen/src/pack.rs +++ b/packed_struct_codegen/src/pack.rs @@ -1,6 +1,3 @@ -extern crate quote; -extern crate syn; - use std::ops::*; use crate::pack_parse::*; @@ -17,7 +14,6 @@ pub enum FieldKind { }, Array { ident: syn::Ident, - size: usize, elements: Vec } } @@ -48,7 +44,6 @@ pub struct PackStruct<'a> { pub fields: Vec, pub num_bytes: usize, pub num_bits: usize, - pub data_struct: &'a syn::DataStruct, pub derive_input: &'a syn::DeriveInput } diff --git a/packed_struct_codegen/src/pack_codegen.rs b/packed_struct_codegen/src/pack_codegen.rs index 2762e67..24a816a 100644 --- a/packed_struct_codegen/src/pack_codegen.rs +++ b/packed_struct_codegen/src/pack_codegen.rs @@ -1,6 +1,4 @@ -extern crate quote; -extern crate syn; - +use quote::quote; use crate::pack::*; use crate::pack_codegen_docs::*; use crate::common::*; @@ -53,14 +51,14 @@ pub fn derive_pack(parsed: &PackStruct) -> syn::Result for field in &parsed.fields { match field { - FieldKind::Regular { ref ident, ref field } => { + FieldKind::Regular { ident, field } => { reg(ident, ident, field)?; unpack_struct_set.push(quote! { #ident }); }, - FieldKind::Array { ref ident, ref elements, .. } => { + FieldKind::Array { ident, elements, .. } => { let mut array_unpacked_elements = vec![]; for (i, field) in elements.iter().enumerate() { let src: syn::ExprIndex = syn::parse_str(&format!("{}[{}]", tokens_to_string(ident), i))?; @@ -187,12 +185,11 @@ fn pack_bits(field: &FieldRegular) -> PackBitsCopy { }; let mut l = 8 - ((packed_field_len as isize*8) - field.bit_width as isize); - let mut dst_byte = start_byte; let mut pack = vec![]; let mut unpack = vec![]; - for i in 0..packed_field_len { + for (i, dst_byte) in (start_byte..start_byte + packed_field_len).enumerate() { let src_mask = ones_u8(l as u8); let bit_shift = emit_shift(shift); pack.push(quote! { @@ -238,7 +235,6 @@ fn pack_bits(field: &FieldRegular) -> PackBitsCopy { }); } - dst_byte += 1; l += 8; } @@ -271,7 +267,7 @@ fn pack_field(name: &dyn quote::ToTokens, field: &FieldRegular) -> proc_macro2:: } }; }, - SerializationWrapper::Integer { ref integer } => { + SerializationWrapper::Integer { integer } => { output = quote! { { use ::packed_struct::types::*; @@ -282,7 +278,7 @@ fn pack_field(name: &dyn quote::ToTokens, field: &FieldRegular) -> proc_macro2:: } }; }, - SerializationWrapper::Endiannes { ref endian } => { + SerializationWrapper::Endiannes { endian } => { output = quote! { { use ::packed_struct::types::*; @@ -298,7 +294,7 @@ fn pack_field(name: &dyn quote::ToTokens, field: &FieldRegular) -> proc_macro2:: quote! { { - { & #output }.pack()? + (& #output).pack()? } } } @@ -312,7 +308,7 @@ fn unpack_field(field: &FieldRegular) -> syn::Result { let mut i = 0; loop { match (wrappers.get(i), wrappers.get(i+1)) { - (Some(SerializationWrapper::Endiannes { ref endian }), Some(SerializationWrapper::Integer { ref integer })) => { + (Some(SerializationWrapper::Endiannes { endian }), Some(SerializationWrapper::Integer { integer })) => { unpack = quote! { use ::packed_struct::types::*; diff --git a/packed_struct_codegen/src/pack_codegen_docs.rs b/packed_struct_codegen/src/pack_codegen_docs.rs index 1deb17b..4b0b5e5 100644 --- a/packed_struct_codegen/src/pack_codegen_docs.rs +++ b/packed_struct_codegen/src/pack_codegen_docs.rs @@ -1,7 +1,7 @@ use crate::pack::*; use crate::common::*; use proc_macro2::Span; -use quote::{ToTokens}; +use quote::{quote, ToTokens}; use syn::parse_quote; use crate::utils::*; @@ -21,7 +21,7 @@ pub fn struct_runtime_formatter(parsed: &PackStruct) -> syn::Result { + FieldKind::Regular { ident, field } => { let name_str = &ident.to_string(); let bits: syn::ExprRange = syn::parse_str(&format!("{}..{}", field.bit_range.start, field.bit_range.end))?; @@ -33,7 +33,7 @@ pub fn struct_runtime_formatter(parsed: &PackStruct) -> syn::Result { + FieldKind::Array { ident, elements, .. } => { for (i, field) in elements.iter().enumerate() { let name_str = format!("{}[{}]", ident, i); let bits: syn::ExprRange = syn::parse_str(&format!("{}..{}", field.bit_range.start, field.bit_range.end))?; @@ -131,10 +131,10 @@ pub fn type_docs(parsed: &PackStruct) -> proc_macro2::TokenStream { for field in &parsed.fields { match field { - FieldKind::Regular { ref ident, ref field } => { + FieldKind::Regular { ident, field } => { emit_field_docs(&field.bit_range, ident.to_string(), &field.ty); }, - FieldKind::Array { ref ident, ref elements, .. } => { + FieldKind::Array { ident, elements, .. } => { for (i, field) in elements.iter().enumerate() { emit_field_docs(&field.bit_range, format!("{}[{}]", ident, i), &field.ty); } diff --git a/packed_struct_codegen/src/pack_parse.rs b/packed_struct_codegen/src/pack_parse.rs index ff27bfe..a31a517 100644 --- a/packed_struct_codegen/src/pack_parse.rs +++ b/packed_struct_codegen/src/pack_parse.rs @@ -1,6 +1,3 @@ -extern crate quote; -extern crate syn; - use crate::pack::*; use crate::pack_parse_attributes::*; @@ -225,7 +222,6 @@ fn parse_field(field: &syn::Field, mp: &FieldMidPositioning, bit_range: &Range Result { -pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result { +pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result> { let attributes = PackStructAttribute::parse_all(&parse_sub_attributes(&ast.attrs, "packed_struct", "packed_field")?); let data_struct = match &ast.data { @@ -429,11 +425,10 @@ pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result { if let Some(struct_size_bytes) = struct_size_bytes { struct_size_bytes * 8 } else { - let last_bit = fields_parsed.iter().map(|f| match f { - FieldKind::Regular { ref field, .. } => field.bit_range_rust.end, - FieldKind::Array { ref elements, .. } => elements.last().unwrap().bit_range_rust.end - }).max().unwrap(); - last_bit + fields_parsed.iter().map(|f| match f { + FieldKind::Regular { field, .. } => field.bit_range_rust.end, + FieldKind::Array { elements, .. } => elements.last().unwrap().bit_range_rust.end + }).max().unwrap() } }; @@ -460,10 +455,10 @@ pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result { }; match field { - FieldKind::Regular { ref field, ref ident } => { + FieldKind::Regular { field, ident } => { find_overlaps(ident.to_string(), &field.bit_range)?; }, - FieldKind::Array { ref ident, ref elements, .. } => { + FieldKind::Array { ident, elements, .. } => { for (i, field) in elements.iter().enumerate() { find_overlaps(format!("{}[{}]", ident, i), &field.bit_range)?; } @@ -474,7 +469,6 @@ pub fn parse_struct(ast: &syn::DeriveInput) -> syn::Result { Ok(PackStruct { derive_input: ast, - data_struct, fields: fields_parsed, num_bytes, num_bits diff --git a/packed_struct_codegen/src/primitive_enum.rs b/packed_struct_codegen/src/primitive_enum.rs index 830f71f..f535804 100644 --- a/packed_struct_codegen/src/primitive_enum.rs +++ b/packed_struct_codegen/src/primitive_enum.rs @@ -1,6 +1,4 @@ -extern crate quote; -extern crate syn; - +use quote::quote; use proc_macro2::Span; use quote::TokenStreamExt; use syn::spanned::Spanned; @@ -55,13 +53,13 @@ pub fn derive(ast: &syn::DeriveInput, mut prim_type: Option) -> syn:: d.suffix.clone() } else if d.negative { let n = d.discriminant as i64; - if n < ::min_value() as i64 { + if n < i32::MIN as i64 { "i64".into() } else { let n = -n; - if n < ::min_value() as i64 { + if n < i16::MIN as i64 { "i32".into() - } else if n < ::min_value() as i64 { + } else if n < i8::MIN as i64 { "i16".into() } else { "i8".into() @@ -69,11 +67,11 @@ pub fn derive(ast: &syn::DeriveInput, mut prim_type: Option) -> syn:: } } else { let n = d.discriminant; - if n > ::max_value() as u64 { + if n > u32::MAX as u64 { "u64".into() - } else if n > ::max_value() as u64 { + } else if n > u16::MAX as u64 { "u32".into() - } else if n > ::max_value() as u64 { + } else if n > u8::MAX as u64 { "u16".into() } else { "u8".into() @@ -239,7 +237,7 @@ fn get_unitary_enum(input: &syn::DeriveInput) -> syn::Result> { } let (discriminant, negative, suffix) = match &variant.discriminant { - Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(ref lit_int), .. }))) => { + Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(lit_int), .. }))) => { (lit_int.base10_parse()?, false, lit_int.suffix().into()) }, Some((_, diff --git a/packed_struct_codegen/src/utils.rs b/packed_struct_codegen/src/utils.rs index f2402af..144a67b 100644 --- a/packed_struct_codegen/src/utils.rs +++ b/packed_struct_codegen/src/utils.rs @@ -19,7 +19,7 @@ impl BitsRange for Range { impl BitsRange for NextBits { fn get_bits_range(&self, packed_bit_width: usize, prev_range: &Option>) -> Range { - if let Some(ref prev_range) = prev_range { + if let Some(prev_range) = prev_range { (prev_range.end + 1)..((prev_range.end + 1) + packed_bit_width - 1) } else { 0..(packed_bit_width - 1) diff --git a/packed_struct_examples/Cargo.toml b/packed_struct_examples/Cargo.toml index 2b6d030..40ad72a 100644 --- a/packed_struct_examples/Cargo.toml +++ b/packed_struct_examples/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "packed_struct_examples" version = "0.1.0" -authors = ["Rudi Benkovic "] publish = false -edition = "2018" +authors.workspace = true +edition.workspace = true +rust-version.workspace = true [dependencies] -packed_struct = { path = "../packed_struct/", features = ["byte_types_64"] } +packed_struct = { workspace = true, features = ["std", "byte_types_64"] } diff --git a/packed_struct_examples/src/lib.rs b/packed_struct_examples/src/lib.rs index a324a22..65d7b76 100644 --- a/packed_struct_examples/src/lib.rs +++ b/packed_struct_examples/src/lib.rs @@ -1,6 +1,3 @@ -#[macro_use] -extern crate packed_struct; - use packed_struct::prelude::*; pub mod example1; diff --git a/packed_struct_nostd_tests/Cargo.toml b/packed_struct_nostd_tests/Cargo.toml index aa2f95e..3f76509 100644 --- a/packed_struct_nostd_tests/Cargo.toml +++ b/packed_struct_nostd_tests/Cargo.toml @@ -2,6 +2,9 @@ name = "packed_struct_nostd_tests" version = "0.1.0" authors = ["Rudi Benkovic "] +publish = false +edition = "2024" +rust-version = "1.85" [dependencies] -packed_struct = { path = "../packed_struct/", default-features = false } \ No newline at end of file +packed_struct = { path = "../packed_struct/", default-features = false } diff --git a/packed_struct_nostd_tests/src/lib.rs b/packed_struct_nostd_tests/src/lib.rs index 780a670..6a8a0e3 100644 --- a/packed_struct_nostd_tests/src/lib.rs +++ b/packed_struct_nostd_tests/src/lib.rs @@ -1,8 +1,5 @@ #![no_std] -#[macro_use] -extern crate packed_struct; - use packed_struct::prelude::*; /// Control register, address 0xA0. @@ -48,8 +45,8 @@ mod tests { fn nostd_usage() { use packed_struct::prelude::*; - use ControlRegister; - use PowerMode; + use crate::ControlRegister; + use crate::PowerMode; let reg = ControlRegister { power_mode: PowerMode::LowPower, diff --git a/packed_struct_tests/Cargo.toml b/packed_struct_tests/Cargo.toml index c16449d..b7d8871 100644 --- a/packed_struct_tests/Cargo.toml +++ b/packed_struct_tests/Cargo.toml @@ -1,11 +1,16 @@ [package] name = "packed_struct_tests" version = "0.1.0" -authors = ["Rudi Benkovic "] publish = false -edition = "2018" +authors.workspace = true +edition.workspace = true +rust-version.workspace = true [dependencies] -packed_struct = { path = "../packed_struct/", features = ["byte_types_64", "use_serde"] } -error-chain = "0.12.0" -serde = "1.0" \ No newline at end of file +packed_struct = { workspace = true, features = ["std", "byte_types_64", "use_serde"] } +error-chain.workspace = true +serde = { workspace = true, features = ["std"] } + +[lints.rust] +# emitted by the error_chain! macro expansion in tests/packing_issue_10.rs +unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_error_description_deprecated)"] } diff --git a/packed_struct_tests/tests/primitive_enum.rs b/packed_struct_tests/tests/primitive_enum.rs index a8eb7b3..bf1a341 100644 --- a/packed_struct_tests/tests/primitive_enum.rs +++ b/packed_struct_tests/tests/primitive_enum.rs @@ -8,6 +8,7 @@ pub enum SelfTestMode { NotAllowed = 3, } +#[allow(dead_code)] #[derive(PrimitiveEnum_u8, Copy, Clone)] enum AddressCommand { PageProgram = 0x02, @@ -15,6 +16,7 @@ enum AddressCommand { Read = 0x03 } +#[allow(dead_code)] #[derive(PrimitiveEnum_u8, Copy, Clone)] enum TestSmall { PageProgram = 0, diff --git a/packed_struct_tests/tests/roundtrip_1.rs b/packed_struct_tests/tests/roundtrip_1.rs index 3fc8dd7..8e06ab1 100644 --- a/packed_struct_tests/tests/roundtrip_1.rs +++ b/packed_struct_tests/tests/roundtrip_1.rs @@ -49,27 +49,27 @@ fn test_roundtrip_1() { for _ in 0..100 { let s = RoundtripAligned { - f1: rnd.rnd_num(u8::max_value() as u64) as u8, - f2: rnd.rnd_num(i8::max_value() as u64) as i8, + f1: rnd.rnd_num(u8::MAX as u64) as u8, + f2: rnd.rnd_num(i8::MAX as u64) as i8, - f3: rnd.rnd_num(u16::max_value() as u64) as u16, - f4: rnd.rnd_num(u16::max_value() as u64) as i16, + f3: rnd.rnd_num(u16::MAX as u64) as u16, + f4: rnd.rnd_num(u16::MAX as u64) as i16, - f5: rnd.rnd_num(u16::max_value() as u64) as u16, - f6: rnd.rnd_num(u16::max_value() as u64) as i16, + f5: rnd.rnd_num(u16::MAX as u64) as u16, + f6: rnd.rnd_num(u16::MAX as u64) as i16, - f7: rnd.rnd_num(u32::max_value() as u64) as u32, - f8: rnd.rnd_num(i32::max_value() as u64) as i32, + f7: rnd.rnd_num(u32::MAX as u64) as u32, + f8: rnd.rnd_num(i32::MAX as u64) as i32, - f9: rnd.rnd_num(u32::max_value() as u64) as u32, - f10: rnd.rnd_num(i32::max_value() as u64) as i32, + f9: rnd.rnd_num(u32::MAX as u64) as u32, + f10: rnd.rnd_num(i32::MAX as u64) as i32, - u64_1: rnd.rnd_num(u64::max_value()), + u64_1: rnd.rnd_num(u64::MAX), - f11: [rnd.rnd_num(u8::max_value() as u64) as u8], - f12: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], - f13: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], - f14: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], + f11: [rnd.rnd_num(u8::MAX as u64) as u8], + f12: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], + f13: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], + f14: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], f15: (rnd.rnd() % 2) == 0 }; diff --git a/packed_struct_tests/tests/roundtrip_2.rs b/packed_struct_tests/tests/roundtrip_2.rs index 8d8c4b4..ce59b22 100644 --- a/packed_struct_tests/tests/roundtrip_2.rs +++ b/packed_struct_tests/tests/roundtrip_2.rs @@ -46,25 +46,25 @@ fn test_roundtrip_2() { for _ in 0..100 { let s = RoundtripUnaligned { - f1: rnd.rnd_num(u8::max_value() as u64) as u8, - f2: rnd.rnd_num(i8::max_value() as u64) as i8, + f1: rnd.rnd_num(u8::MAX as u64) as u8, + f2: rnd.rnd_num(i8::MAX as u64) as i8, - f3: rnd.rnd_num(u16::max_value() as u64) as u16, - f4: rnd.rnd_num(u16::max_value() as u64) as i16, + f3: rnd.rnd_num(u16::MAX as u64) as u16, + f4: rnd.rnd_num(u16::MAX as u64) as i16, - f5: rnd.rnd_num(u16::max_value() as u64) as u16, - f6: rnd.rnd_num(u16::max_value() as u64) as i16, + f5: rnd.rnd_num(u16::MAX as u64) as u16, + f6: rnd.rnd_num(u16::MAX as u64) as i16, - f7: rnd.rnd_num(u32::max_value() as u64) as u32, - f8: rnd.rnd_num(i32::max_value() as u64) as i32, + f7: rnd.rnd_num(u32::MAX as u64) as u32, + f8: rnd.rnd_num(i32::MAX as u64) as i32, - f9: rnd.rnd_num(u32::max_value() as u64) as u32, - f10: rnd.rnd_num(i32::max_value() as u64) as i32, + f9: rnd.rnd_num(u32::MAX as u64) as u32, + f10: rnd.rnd_num(i32::MAX as u64) as i32, - f11: [rnd.rnd_num(u8::max_value() as u64) as u8], - f12: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], - f13: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], - f14: [rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8, rnd.rnd_num(u8::max_value() as u64) as u8], + f11: [rnd.rnd_num(u8::MAX as u64) as u8], + f12: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], + f13: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], + f14: [rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8, rnd.rnd_num(u8::MAX as u64) as u8], f15: (rnd.rnd() % 2) == 0 }; diff --git a/packed_struct_tests/tests/test_serde.rs b/packed_struct_tests/tests/test_serde.rs index 0a07426..4086aee 100644 --- a/packed_struct_tests/tests/test_serde.rs +++ b/packed_struct_tests/tests/test_serde.rs @@ -1,7 +1,3 @@ -extern crate packed_struct; -extern crate serde; - - use packed_struct::prelude::*; #[test]