]> git.lizzy.rs Git - rust.git/commitdiff
Recommend `Ipv6Addr::to_ipv4_mapped` over `Ipv6Addr::to_ipv4`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Tue, 10 May 2022 16:08:46 +0000 (18:08 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Tue, 10 May 2022 16:08:46 +0000 (18:08 +0200)
Fixes #96718.

library/std/src/net/ip.rs

index 02ab0129e0fbd5125e0a03dbd0e83b2c91ccf98d..46004c9914200d455545d91bae456410eecc6dbc 100644 (file)
@@ -138,7 +138,8 @@ pub struct Ipv4Addr {
 ///
 /// To convert from an IPv4 address to an IPv4-mapped IPv6 address, use [`Ipv4Addr::to_ipv6_mapped`].
 /// Use [`Ipv6Addr::to_ipv4`] to convert an IPv4-mapped IPv6 address to the canonical IPv4 address.
-/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`.
+/// Note that this will also convert the IPv6 loopback address `::1` to `0.0.0.1`. Use
+/// [`Ipv6Addr::to_ipv4_mapped`] to avoid this.
 ///
 /// [IETF RFC 4291 Section 2.5.5.2]: https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5.2
 ///
@@ -1672,7 +1673,8 @@ pub const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> {
     /// or an [IPv4-mapped] address as defined in [IETF RFC 4291 section 2.5.5.2],
     /// otherwise returns [`None`].
     ///
-    /// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`.
+    /// Note that this will return an [`IPv4` address] for the IPv6 loopback address `::1`. Use
+    /// [`Ipv6Addr::to_ipv4_mapped`] to avoid this.
     ///
     /// `::a.b.c.d` and `::ffff:a.b.c.d` become `a.b.c.d`. `::1` becomes `0.0.0.1`.
     /// All addresses *not* starting with either all zeroes or `::ffff` will return `None`.