diff options
| author | Markus Reiter <me@reitermark.us> | 2022-08-16 19:32:00 +0200 |
|---|---|---|
| committer | Markus Reiter <me@reitermark.us> | 2022-08-16 19:32:00 +0200 |
| commit | 44d62425b9e08c1eebd329766b5e4dd7f8bc3216 (patch) | |
| tree | 3643757f1dbba24c52f37229580b0f547742f574 | |
| parent | 31540f5e15d5785a61d96869b373f7ed4d4a3654 (diff) | |
| download | rust-44d62425b9e08c1eebd329766b5e4dd7f8bc3216.tar.gz rust-44d62425b9e08c1eebd329766b5e4dd7f8bc3216.zip | |
Simplify `IpDisplayBuffer` API.
| -rw-r--r-- | library/std/src/net/ip.rs | 8 | ||||
| -rw-r--r-- | library/std/src/net/ip/display_buffer.rs | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 198dcff12b9..189754a161e 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -999,7 +999,9 @@ impl fmt::Display for Ipv4Addr { if fmt.precision().is_none() && fmt.width().is_none() { write!(fmt, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]) } else { - let mut buf = IpDisplayBuffer::new(b"255.255.255.255"); + const LONGEST_IPV4_ADDR: &str = "255.255.255.255"; + + let mut buf = IpDisplayBuffer::<{ LONGEST_IPV4_ADDR.len() }>::new(); // Buffer is long enough for the longest possible IPv4 address, so this should never fail. write!(buf, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap(); @@ -1778,7 +1780,9 @@ impl fmt::Display for Ipv6Addr { } } } else { - let mut buf = IpDisplayBuffer::new(b"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); + const LONGEST_IPV6_ADDR: &str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"; + + let mut buf = IpDisplayBuffer::<{ LONGEST_IPV6_ADDR.len() }>::new(); // Buffer is long enough for the longest possible IPv6 address, so this should never fail. write!(buf, "{}", self).unwrap(); diff --git a/library/std/src/net/ip/display_buffer.rs b/library/std/src/net/ip/display_buffer.rs index 65f11b8ae93..bd852d5da8e 100644 --- a/library/std/src/net/ip/display_buffer.rs +++ b/library/std/src/net/ip/display_buffer.rs @@ -9,12 +9,12 @@ pub struct IpDisplayBuffer<const SIZE: usize> { } impl<const SIZE: usize> IpDisplayBuffer<SIZE> { - #[inline(always)] - pub const fn new(_ip: &[u8; SIZE]) -> Self { - Self { buf: MaybeUninit::uninit_array::<SIZE>(), len: 0 } + #[inline] + pub const fn new() -> Self { + Self { buf: MaybeUninit::uninit_array(), len: 0 } } - #[inline(always)] + #[inline] pub fn as_str(&self) -> &str { // SAFETY: `buf` is only written to by the `fmt::Write::write_str` implementation // which writes a valid UTF-8 string to `buf` and correctly sets `len`. |
