diff options
| author | Lukas Kalbertodt <lukas.kalbertodt@gmail.com> | 2020-07-16 21:29:09 +0200 |
|---|---|---|
| committer | Lukas Kalbertodt <lukas.kalbertodt@gmail.com> | 2020-07-28 17:48:47 +0200 |
| commit | 6293dca1e880394d90fe80055216328fe4d9702e (patch) | |
| tree | 1fb1c8ab21bb65f2760d0eb20a9945ca8c95adec /library/std/src | |
| parent | 1f5d69daccd1f04e42886d9aaf513f2691132d17 (diff) | |
| download | rust-6293dca1e880394d90fe80055216328fe4d9702e.tar.gz rust-6293dca1e880394d90fe80055216328fe4d9702e.zip | |
Change Debug impl of SocketAddr and IpAddr to match their Display output
This has already been done for `SocketAddrV4`, `SocketAddrV6`,
`IpAddrV4` and `IpAddrV6`. I don't see a point to keep the rather bad
to read derived impl, especially when pretty printing:
V4(
127.0.0.1
)
From the `Display`, one can easily and unambiguously see if it's V4 or
V6. Using `Display` as `Debug` is very convenient for configuration
structs (e.g. for webservers) that often just have a `derive(Debug)`
and are printed that way to the user.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/net/addr.rs | 9 | ||||
| -rw-r--r-- | library/std/src/net/ip.rs | 9 |
2 files changed, 16 insertions, 2 deletions
diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs index 8c8d1aadf48..4f751656e09 100644 --- a/library/std/src/net/addr.rs +++ b/library/std/src/net/addr.rs @@ -37,7 +37,7 @@ use crate::vec; /// assert_eq!(socket.port(), 8080); /// assert_eq!(socket.is_ipv4(), true); /// ``` -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[stable(feature = "rust1", since = "1.0.0")] pub enum SocketAddr { /// An IPv4 socket address. @@ -598,6 +598,13 @@ impl fmt::Display for SocketAddr { } #[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for SocketAddr { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, fmt) + } +} + +#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for SocketAddrV4 { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Fast path: if there's no alignment stuff, write to the output buffer diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 0f0be2c4883..c27a33bc109 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -39,7 +39,7 @@ use crate::sys_common::{AsInner, FromInner}; /// assert_eq!(localhost_v4.is_ipv4(), true); /// ``` #[stable(feature = "ip_addr", since = "1.7.0")] -#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)] pub enum IpAddr { /// An IPv4 address. #[stable(feature = "ip_addr", since = "1.7.0")] @@ -811,6 +811,13 @@ impl fmt::Display for IpAddr { } } +#[stable(feature = "ip_addr", since = "1.7.0")] +impl fmt::Debug for IpAddr { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, fmt) + } +} + #[stable(feature = "ip_from_ip", since = "1.16.0")] impl From<Ipv4Addr> for IpAddr { /// Copies this address to a new `IpAddr::V4`. |
