diff options
| author | Nathan West <Lucretiel@gmail.com> | 2020-05-22 15:59:38 -0400 |
|---|---|---|
| committer | Nathan West <Lucretiel@gmail.com> | 2020-05-29 00:50:36 -0400 |
| commit | 06a97a027a21f6fe67f91b0630291fbb62d2de83 (patch) | |
| tree | 5b9bfb2b34605161297db426cdc86cf4b4c8f36b /src/libstd | |
| parent | defbd845a33cf3c61c3af77aae474964f92e34bb (diff) | |
| download | rust-06a97a027a21f6fe67f91b0630291fbb62d2de83.tar.gz rust-06a97a027a21f6fe67f91b0630291fbb62d2de83.zip | |
Clarify comment message & MAX_LENGTH const
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net/addr.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 2febe157a50..b780340884e 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -605,11 +605,14 @@ impl fmt::Display for SocketAddrV4 { if f.precision().is_none() && f.width().is_none() { write!(f, "{}:{}", self.ip(), self.port()) } else { - const IPV4_SOCKET_BUF_LEN: usize = 21; + const IPV4_SOCKET_BUF_LEN: usize = (3 * 4) // the segments + + 3 // the separators + + 1 + 5; // the port let mut buf = [0; IPV4_SOCKET_BUF_LEN]; let mut buf_slice = &mut buf[..]; - // Unwrap is fine because writing to a buffer is infallible + // Unwrap is fine because writing to a sufficiently-sized + // buffer is infallible write!(buf_slice, "{}:{}", self.ip(), self.port()).unwrap(); let len = IPV4_SOCKET_BUF_LEN - buf_slice.len(); @@ -643,7 +646,8 @@ impl fmt::Display for SocketAddrV6 { let mut buf = [0; IPV6_SOCKET_BUF_LEN]; let mut buf_slice = &mut buf[..]; - // Unwrap is fine because writing to a buffer is infallible + // Unwrap is fine because writing to a sufficiently-sized + // buffer is infallible write!(buf_slice, "[{}]:{}", self.ip(), self.port()).unwrap(); let len = IPV6_SOCKET_BUF_LEN - buf_slice.len(); |
