network: Move serde code down the file
What changed, and why it matters
This commit simply rearranges code within a single file. It moves the Display, FromStr, and AsRef implementations for the Network type to appear earlier in the file, and moves the serde-related code lower down. No logic, behavior, or security properties of the code were changed.
No action required. This is a non-functional code-style/refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure code relocation in network/src/lib.rs. The fmt::Display, FromStr, and AsRef
Changed components
network/src/lib.rsInspect captured patch +28 / −28
diff --git a/network/src/lib.rs b/network/src/lib.rs
index f974e88b..48a02d7f 100644
--- a/network/src/lib.rs
+++ b/network/src/lib.rs
@@ -151,6 +151,34 @@ impl Network {
}
}
+impl fmt::Display for Network {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+ write!(f, "{}", self.as_display_str())
+ }
+}
+
+impl FromStr for Network {
+ type Err = ParseNetworkError;
+
+ /// Parses a network identifier string into a `Network`.
+ #[inline]
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "bitcoin" => Ok(Self::Bitcoin),
+ // For user-side compatibility, testnet3 is retained as testnet
+ "testnet" => Ok(Self::Testnet(TestnetVersion::V3)),
+ "testnet4" => Ok(Self::Testnet(TestnetVersion::V4)),
+ "signet" => Ok(Self::Signet),
+ "regtest" => Ok(Self::Regtest),
+ _ => Err(ParseNetworkError(InputString::from(s))),
+ }
+ }
+}
+
+impl AsRef<Self> for Network {
+ fn as_ref(&self) -> &Self { self }
+}
+
#[cfg(feature = "serde")]
impl Serialize for Network {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -188,12 +216,6 @@ impl<'de> Deserialize<'de> for Network {
}
}
-impl fmt::Display for Network {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
- write!(f, "{}", self.as_display_str())
- }
-}
-
#[cfg(feature = "serde")]
pub mod as_core_arg {
//! Serde helper module for Bitcoin Core `-chain` argument serialization.
@@ -259,28 +281,6 @@ pub mod as_core_arg {
}
}
-impl FromStr for Network {
- type Err = ParseNetworkError;
-
- /// Parses a network identifier string into a `Network`.
- #[inline]
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- match s {
- "bitcoin" => Ok(Self::Bitcoin),
- // For user-side compatibility, testnet3 is retained as testnet
- "testnet" => Ok(Self::Testnet(TestnetVersion::V3)),
- "testnet4" => Ok(Self::Testnet(TestnetVersion::V4)),
- "signet" => Ok(Self::Signet),
- "regtest" => Ok(Self::Regtest),
- _ => Err(ParseNetworkError(InputString::from(s))),
- }
- }
-}
-
-impl AsRef<Self> for Network {
- fn as_ref(&self) -> &Self { self }
-}
-
#[cfg(feature = "arbitrary")]
impl<'a> Arbitrary<'a> for NetworkKind {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
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.