network: Move errors to error submodule
What changed, and why it matters
This commit is a routine code reorganization. It moves the definition of a parsing error type into a new 'error' submodule while keeping the same public name available at the top level. There is no security-relevant change.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates ParseNetworkError from the top-level network/src/lib.rs into a new pub mod error submodule and re-exports it at the top level with #[doc(no_inline)]. The struct’s visibility for its internal InputString field changes from private (implicit) to pub(super), but the type remains non_exhaustive and its public API behavior is unchanged. No logic, parsing rules, or error handling changed.
Changed components
network/src/lib.rsParseNetworkErrorInspect captured patch +28 / −17
diff --git a/network/src/lib.rs b/network/src/lib.rs
index 395f4e46..16b80ad6 100644
--- a/network/src/lib.rs
+++ b/network/src/lib.rs
@@ -27,6 +27,10 @@ use internals::error::InputString;
#[cfg(feature = "serde")]
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};
+#[rustfmt::skip] // Keep public re-exports separate.
+#[doc(no_inline)]
+pub use self::error::ParseNetworkError;
+
/// What kind of network we are on.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -238,23 +242,6 @@ pub mod as_core_arg {
}
}
-/// An error in parsing network string.
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[non_exhaustive]
-pub struct ParseNetworkError(InputString);
-
-impl fmt::Display for ParseNetworkError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- // Outputs 'failed to parse <input string> as network'.
- write!(f, "{}", self.0.display_cannot_parse("network"))
- }
-}
-
-#[cfg(feature = "std")]
-impl std::error::Error for ParseNetworkError {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
-}
-
impl FromStr for Network {
type Err = ParseNetworkError;
@@ -286,6 +273,30 @@ impl<'a> Arbitrary<'a> for NetworkKind {
}
}
+/// Error types for the network.
+pub mod error {
+ use core::fmt;
+
+ use internals::error::InputString;
+
+ /// An error in parsing network string.
+ #[derive(Debug, Clone, PartialEq, Eq)]
+ #[non_exhaustive]
+ pub struct ParseNetworkError(pub(super) InputString);
+
+ impl fmt::Display for ParseNetworkError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ // Outputs 'failed to parse <input string> as network'.
+ write!(f, "{}", self.0.display_cannot_parse("network"))
+ }
+ }
+
+ #[cfg(feature = "std")]
+ impl std::error::Error for ParseNetworkError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+ }
+}
+
#[cfg(test)]
mod tests {
#[cfg(feature = "std")]
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.