io: Make error module public and re-export errors no-inline
What changed, and why it matters
This commit is a routine code reorganization. It moves an existing error type (ReadError) into a dedicated public submodule and changes how it is re-exported in documentation. There is no functional change to how the code behaves, no bug fix, and no security improvement or regression.
No security action required. Treat as a normal API/documentation refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the io crate’s error types: the previously private mod error is made pub mod error, ReadError is relocated from lib.rs to error.rs, and crate-root re-exports now use #[doc(no_inline)]. The Error and ErrorKind types remain exported. The diff shows only moves and doc-attribute additions; no logic, visibility of types to downstream code, or trait implementations are substantively altered.
Changed components
io/src/error.rsio/src/lib.rsInspect captured patch +41 / −38
diff --git a/io/src/error.rs b/io/src/error.rs
index 4cfdd289..aac4012e 100644
--- a/io/src/error.rs
+++ b/io/src/error.rs
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
+//! Error types for the `io` crate.
+
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
@@ -201,6 +203,42 @@ define_errorkind!(
Other
);
+/// An error that can occur when reading and decoding from a buffered reader.
+#[derive(Debug)]
+pub enum ReadError<D> {
+ /// An I/O error occurred while reading from the reader.
+ Io(Error),
+ /// The decoder encountered an error while parsing the data.
+ Decode(D),
+}
+
+impl<D: fmt::Display> fmt::Display for ReadError<D> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::Io(e) => write!(f, "I/O error: {}", e),
+ Self::Decode(e) => write!(f, "decode error: {}", e),
+ }
+ }
+}
+
+#[cfg(feature = "std")]
+impl<D> std::error::Error for ReadError<D>
+where
+ D: fmt::Debug + fmt::Display + std::error::Error + 'static,
+{
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::Io(e) => Some(e),
+ Self::Decode(e) => Some(e),
+ }
+ }
+}
+
+#[cfg(feature = "std")]
+impl<D> From<Error> for ReadError<D> {
+ fn from(e: Error) -> Self { Self::Io(e) }
+}
+
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
mod sealed {
diff --git a/io/src/lib.rs b/io/src/lib.rs
index 8212135e..ee45dc83 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -33,7 +33,7 @@ pub extern crate hashes;
#[cfg(feature = "std")]
mod bridge;
-mod error;
+pub mod error;
#[cfg(feature = "hashes")]
mod hash;
@@ -48,7 +48,8 @@ use std::vec::Vec;
use encoding::{Decodable, Decoder, Encoder};
#[rustfmt::skip] // Keep public re-exports separate.
-pub use self::error::{Error, ErrorKind};
+#[doc(no_inline)]
+pub use self::error::{Error, ErrorKind, ReadError};
#[cfg(feature = "std")]
pub use self::bridge::{FromStd, ToStd};
#[cfg(feature = "hashes")]
@@ -613,42 +614,6 @@ where
decoder.end().map_err(ReadError::Decode)
}
-/// An error that can occur when reading and decoding from a buffered reader.
-#[derive(Debug)]
-pub enum ReadError<D> {
- /// An I/O error occurred while reading from the reader.
- Io(Error),
- /// The decoder encountered an error while parsing the data.
- Decode(D),
-}
-
-impl<D: core::fmt::Display> core::fmt::Display for ReadError<D> {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self {
- Self::Io(e) => write!(f, "I/O error: {}", e),
- Self::Decode(e) => write!(f, "decode error: {}", e),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl<D> std::error::Error for ReadError<D>
-where
- D: core::fmt::Debug + core::fmt::Display + std::error::Error + 'static,
-{
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Self::Io(e) => Some(e),
- Self::Decode(e) => Some(e),
- }
- }
-}
-
-#[cfg(feature = "std")]
-impl<D> From<Error> for ReadError<D> {
- fn from(e: Error) -> Self { Self::Io(e) }
-}
-
#[cfg(feature = "std")]
include!("../../include/newtype.rs"); // Explained in `REPO_DIR/docs/README.md`.
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.