Open
Conversation
There was a problem hiding this comment.
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::Errorwith unconditionalimpl ::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 theDisplaytrait (which is already implemented forPackingError). ModernErrortrait implementations typically don't need to overridedescription()as it defaults to returning theDisplayoutput. 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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].