units: Move sequence module errors to error submodule
What changed, and why it matters
This commit is a straightforward internal code reorganization. It moves an error type related to decoding transaction sequence numbers into a new 'error' submodule and re-exports it. There is no functional change to how the library behaves, and no security issue is present.
No action required. This is a non-security refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors units/src/sequence.rs by moving SequenceDecoderError and its trait implementations into a new error submodule. It adds a pub use self::error::SequenceDecoderError re-export and changes the inner field visibility from private (encoding::UnexpectedEofError) to pub(super). The logic of the error type and its Display/Error implementations is unchanged. This is purely a structural/API-consistency cleanup.
Changed components
units/src/sequence.rsInspect captured patch +32 / −20
diff --git a/units/src/sequence.rs b/units/src/sequence.rs
index b6fcc1ad..0007a8e4 100644
--- a/units/src/sequence.rs
+++ b/units/src/sequence.rs
@@ -14,14 +14,10 @@
//! [BIP-0068]: <https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki>
//! [BIP-0125]: <https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki>
-#[cfg(feature = "encoding")]
-use core::convert::Infallible;
use core::fmt;
#[cfg(feature = "arbitrary")]
use arbitrary::{Arbitrary, Unstructured};
-#[cfg(feature = "encoding")]
-use internals::write_err;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@@ -29,6 +25,11 @@ use crate::locktime::relative::error::TimeOverflowError;
use crate::locktime::relative::{self, NumberOf512Seconds};
use crate::parse_int::{self, PrefixedHexError, UnprefixedHexError};
+#[rustfmt::skip] // Keep public re-exports separate.
+#[cfg(feature = "encoding")]
+#[doc(no_inline)]
+pub use self::error::SequenceDecoderError;
+
/// Bitcoin transaction input sequence number.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -314,26 +315,37 @@ impl encoding::Decodable for Sequence {
fn decoder() -> Self::Decoder { SequenceDecoder(encoding::ArrayDecoder::<4>::new()) }
}
-/// An error consensus decoding an `Sequence`.
-#[cfg(feature = "encoding")]
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct SequenceDecoderError(encoding::UnexpectedEofError);
+/// Error types for input sequence numbers.
+pub mod error {
+ #[cfg(feature = "encoding")]
+ use core::convert::Infallible;
+ #[cfg(feature = "encoding")]
+ use core::fmt;
-#[cfg(feature = "encoding")]
-impl From<Infallible> for SequenceDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ #[cfg(feature = "encoding")]
+ use internals::write_err;
-#[cfg(feature = "encoding")]
-impl fmt::Display for SequenceDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write_err!(f, "sequence decoder error"; self.0)
+ /// An error consensus decoding an `Sequence`.
+ #[cfg(feature = "encoding")]
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct SequenceDecoderError(pub(super) encoding::UnexpectedEofError);
+
+ #[cfg(feature = "encoding")]
+ impl From<Infallible> for SequenceDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
}
-}
-#[cfg(all(feature = "std", feature = "encoding"))]
-impl std::error::Error for SequenceDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ #[cfg(feature = "encoding")]
+ impl fmt::Display for SequenceDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write_err!(f, "sequence decoder error"; self.0)
+ }
+ }
+
+ #[cfg(all(feature = "std", feature = "encoding"))]
+ impl std::error::Error for SequenceDecoderError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ }
}
#[cfg(feature = "arbitrary")]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.