units: Move time module errors to error submodule
What changed, and why it matters
This commit is a routine code cleanup in the rust-bitcoin library. It moves an error type related to decoding Bitcoin block timestamps into a new 'error' submodule and re-exports it. There is no change to how the code behaves, no bug fix, and no security improvement or vulnerability introduced.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors units/src/time.rs by relocating BlockTimeDecoderError and its trait implementations into a new error submodule. It adds a pub use self::error::BlockTimeDecoderError re-export with #[doc(no_inline)] and changes the error’s internal field visibility from private (encoding::UnexpectedEofError) to pub(super). The change is purely organizational and API-preserving.
Changed components
units/src/time.rsInspect captured patch +32 / −20
diff --git a/units/src/time.rs b/units/src/time.rs
index 9a16ed25..a3fa5f92 100644
--- a/units/src/time.rs
+++ b/units/src/time.rs
@@ -7,19 +7,20 @@
//! This differs from other UNIX timestamps in that we only use non-negative values. The Epoch
//! pre-dates Bitcoin so timestamps before this are not useful for block timestamps.
-#[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, Deserializer, Serialize, Serializer};
use crate::parse_int::{self, PrefixedHexError, UnprefixedHexError};
+#[rustfmt::skip] // Keep public re-exports separate.
+#[cfg(feature = "encoding")]
+#[doc(no_inline)]
+pub use self::error::BlockTimeDecoderError;
+
mod encapsulate {
/// A Bitcoin block timestamp.
///
@@ -172,26 +173,37 @@ impl encoding::Decodable for BlockTime {
fn decoder() -> Self::Decoder { BlockTimeDecoder(encoding::ArrayDecoder::<4>::new()) }
}
-/// An error consensus decoding an `BlockTime`.
-#[cfg(feature = "encoding")]
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub struct BlockTimeDecoderError(encoding::UnexpectedEofError);
+/// Error types for block times.
+pub mod error {
+ #[cfg(feature = "encoding")]
+ use core::convert::Infallible;
+ #[cfg(feature = "encoding")]
+ use core::fmt;
-#[cfg(feature = "encoding")]
-impl From<Infallible> for BlockTimeDecoderError {
- fn from(never: Infallible) -> Self { match never {} }
-}
+ #[cfg(feature = "encoding")]
+ use internals::write_err;
-#[cfg(feature = "encoding")]
-impl fmt::Display for BlockTimeDecoderError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write_err!(f, "block time decoder error"; self.0)
+ /// An error consensus decoding an `BlockTime`.
+ #[cfg(feature = "encoding")]
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ pub struct BlockTimeDecoderError(pub(super) encoding::UnexpectedEofError);
+
+ #[cfg(feature = "encoding")]
+ impl From<Infallible> for BlockTimeDecoderError {
+ fn from(never: Infallible) -> Self { match never {} }
}
-}
-#[cfg(all(feature = "std", feature = "encoding"))]
-impl std::error::Error for BlockTimeDecoderError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
+ #[cfg(feature = "encoding")]
+ impl fmt::Display for BlockTimeDecoderError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write_err!(f, "block time decoder error"; self.0)
+ }
+ }
+
+ #[cfg(all(feature = "std", feature = "encoding"))]
+ impl std::error::Error for BlockTimeDecoderError {
+ 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.