Skip to content

Commit 69de693

Browse files
committed
Clarify docs on what IPv4 octal addresses are
The way octal literals are written in IP addresses differs from the way they are written in Rust code, so the way that octal/hex literals in IPs are written is explictly mentioned.
1 parent 734bfde commit 69de693

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

library/std/src/net/ip.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub enum IpAddr {
5959
///
6060
/// `Ipv4Addr` provides a [`FromStr`] implementation. The four octets are in decimal
6161
/// notation, divided by `.` (this is called "dot-decimal notation").
62-
/// Notably, octal numbers and hexadecimal numbers are not allowed per [IETF RFC 6943].
62+
/// Notably, octal numbers (which are indicated with a leading `0`) and hexadecimal numbers (which
63+
/// are indicated with a leading `0x`) are not allowed per [IETF RFC 6943].
6364
///
6465
/// [IETF RFC 6943]: https://tools.ietf.org/html/rfc6943#section-3.1.1
6566
/// [`FromStr`]: crate::str::FromStr
@@ -72,6 +73,8 @@ pub enum IpAddr {
7273
/// let localhost = Ipv4Addr::new(127, 0, 0, 1);
7374
/// assert_eq!("127.0.0.1".parse(), Ok(localhost));
7475
/// assert_eq!(localhost.is_loopback(), true);
76+
/// assert!("012.004.002.000".parse::<Ipv4Addr>().is_err()); // all octets are in octal
77+
/// assert!("0xcb.0x0.0x71.0x00".parse::<Ipv4Addr>().is_err()); // all octets are in hex
7578
/// ```
7679
#[derive(Copy)]
7780
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)