Skip to content

Conversation

@bitdriftr
Copy link

Hello, I faced an issue where PackingError does not implement error without the std feature. I am using #![no_std] and I need PackingError to implement Error. The good news is, there is no need for std to implement Error. This PR is a quick and easy fix for this problem which allows PackingError to implement Error in #![no_std].

Copilot AI review requested due to automatic review settings December 7, 2025 13:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to enable PackingError to implement the Error trait in #![no_std] environments by switching from std::error::Error to core::error::Error and removing the #[cfg(feature="std")] guard. While the goal is valid and addresses a real need for no_std compatibility, there is a critical compatibility issue with the current implementation.

Key changes:

  • Replaces #[cfg(feature="std")] impl ::std::error::Error with unconditional impl ::core::error::Error
  • Enables Error trait implementation in no_std environments
Comments suppressed due to low confidence (1)

packed_struct/src/packing.rs:83

  • The description() method has been deprecated since Rust 1.42.0 in favor of implementing the Display trait (which is already implemented for PackingError). Modern Error trait implementations typically don't need to override description() as it defaults to returning the Display output. Consider removing this method implementation to follow current best practices.
    fn description(&self) -> &str {
        match *self {
            PackingError::InvalidValue => "Invalid value",
            PackingError::BitsError => "Bits error",
            PackingError::BufferTooSmall => "Buffer too small",            
            PackingError::BufferSizeMismatch { .. } => "Buffer size mismatched",
            PackingError::NotImplemented => "Not implemented",
            PackingError::InstanceRequiredForSize => "This structure's packing size can't be determined statically, an instance is required.",
            PackingError::BufferModMismatch { .. } => "The structure's size is not a multiple of the item's size",
            PackingError::SliceIndexingError { .. } => "Failed to index into a slice",
            PackingError::MoreThanOneDynamicType => "Only one dynamically sized type is supported in the tuple",
            PackingError::InternalError => "Internal error"
        }
    }
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant