Auto merge of #30215 - SimonSapin:ipv6-display-alloc, r=brson
This commit is contained in:
commit
9f715e9892
@ -13,8 +13,6 @@
|
|||||||
be stable",
|
be stable",
|
||||||
issue = "27709")]
|
issue = "27709")]
|
||||||
|
|
||||||
use prelude::v1::*;
|
|
||||||
|
|
||||||
use cmp::Ordering;
|
use cmp::Ordering;
|
||||||
use fmt;
|
use fmt;
|
||||||
use hash;
|
use hash;
|
||||||
@ -446,17 +444,19 @@ impl fmt::Display for Ipv6Addr {
|
|||||||
let (zeros_at, zeros_len) = find_zero_slice(&self.segments());
|
let (zeros_at, zeros_len) = find_zero_slice(&self.segments());
|
||||||
|
|
||||||
if zeros_len > 1 {
|
if zeros_len > 1 {
|
||||||
fn fmt_subslice(segments: &[u16]) -> String {
|
fn fmt_subslice(segments: &[u16], fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
segments
|
if !segments.is_empty() {
|
||||||
.iter()
|
try!(write!(fmt, "{:x}", segments[0]));
|
||||||
.map(|&seg| format!("{:x}", seg))
|
for &seg in &segments[1..] {
|
||||||
.collect::<Vec<String>>()
|
try!(write!(fmt, ":{:x}", seg));
|
||||||
.join(":")
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(fmt, "{}::{}",
|
try!(fmt_subslice(&self.segments()[..zeros_at], fmt));
|
||||||
fmt_subslice(&self.segments()[..zeros_at]),
|
try!(fmt.write_str("::"));
|
||||||
fmt_subslice(&self.segments()[zeros_at + zeros_len..]))
|
fmt_subslice(&self.segments()[zeros_at + zeros_len..], fmt)
|
||||||
} else {
|
} else {
|
||||||
let &[a, b, c, d, e, f, g, h] = &self.segments();
|
let &[a, b, c, d, e, f, g, h] = &self.segments();
|
||||||
write!(fmt, "{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}",
|
write!(fmt, "{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user