Rollup merge of #81202 - lzutao:dbg_ipv6, r=Amanieu
Don't prefix 0x for each segments in `dbg!(Ipv6)` Fixes #81182
This commit is contained in:
commit
950ed27e8b
|
@ -1610,11 +1610,11 @@ impl fmt::Display for Ipv6Addr {
|
||||||
/// Write a colon-separated part of the address
|
/// Write a colon-separated part of the address
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
|
fn fmt_subslice(f: &mut fmt::Formatter<'_>, chunk: &[u16]) -> fmt::Result {
|
||||||
if let Some(first) = chunk.first() {
|
if let Some((first, tail)) = chunk.split_first() {
|
||||||
fmt::LowerHex::fmt(first, f)?;
|
write!(f, "{:x}", first)?;
|
||||||
for segment in &chunk[1..] {
|
for segment in tail {
|
||||||
f.write_char(':')?;
|
f.write_char(':')?;
|
||||||
fmt::LowerHex::fmt(segment, f)?;
|
write!(f, "{:x}", segment)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -166,6 +166,9 @@ fn ipv6_addr_to_string() {
|
||||||
|
|
||||||
// two runs of zeros, equal length
|
// two runs of zeros, equal length
|
||||||
assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string());
|
assert_eq!("1::4:5:0:0:8", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8).to_string());
|
||||||
|
|
||||||
|
// don't prefix `0x` to each segment in `dbg!`.
|
||||||
|
assert_eq!("1::4:5:0:0:8", &format!("{:#?}", Ipv6Addr::new(1, 0, 0, 4, 5, 0, 0, 8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue