Skip to content

Commit 322a149

Browse files
committed
Auto merge of #96649 - tbu-:pr_to_ipv4_loopback_doc, r=m-ou-se
Make it clear that `to_ipv4` returns an IPv4 address for the IPv6 loopback
2 parents 3d18f94 + ed95d50 commit 322a149

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/std/src/net/ip.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub struct Ipv4Addr {
138138
///
139139
/// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`].
140140
/// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address.
141+
/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`.
141142
///
142143
/// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
143144
///
@@ -1673,7 +1674,9 @@ impl Ipv6Addr {
16731674
/// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2],
16741675
/// otherwise returns [`None`].
16751676
///
1676-
/// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`
1677+
/// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`.
1678+
///
1679+
/// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`.
16771680
/// All addresses *not* starting with either all zeroes or `::ffff` will return `None`.
16781681
///
16791682
/// [`IPv4` address]: Ipv4Addr

0 commit comments

Comments
 (0)