Rollup merge of #131790 - nmathewson:doc_socketaddr_representation, r… · qinheping/verify-rust-std@0ae2951 (original) (raw)
`@@ -49,6 +49,15 @@ pub enum SocketAddr {
`
49
49
`/// [IETF RFC 793]: https://tools.ietf.org/html/rfc793
`
50
50
`` /// [IPv4
address]: Ipv4Addr
``
51
51
`///
`
``
52
`+
/// # Textual representation
`
``
53
`+
///
`
``
54
`` +
/// SocketAddrV4
provides a FromStr
implementation.
``
``
55
`+
/// It accepts an IPv4 address in its [textual representation], followed by a
`
``
56
`` +
/// single :
, followed by the port encoded as a decimal integer. Other
``
``
57
`+
/// formats are not accepted.
`
``
58
`+
///
`
``
59
`+
/// [textual representation]: Ipv4Addr#textual-representation
`
``
60
`+
///
`
52
61
`/// # Examples
`
53
62
`///
`
54
63
```` /// ```
`@@ -82,6 +91,32 @@ pub struct SocketAddrV4 {
`
`82`
`91`
`/// [IETF RFC 2553, Section 3.3]: https://tools.ietf.org/html/rfc2553#section-3.3
`
`83`
`92`
`` /// [`IPv6` address]: Ipv6Addr
``
`84`
`93`
`///
`
``
`94`
`+
/// # Textual representation
`
``
`95`
`+
///
`
``
`96`
`` +
/// `SocketAddrV6` provides a [`FromStr`](crate::str::FromStr) implementation,
``
``
`97`
`+
/// based on the bracketed format recommended by [IETF RFC 5952],
`
``
`98`
`+
/// with scope identifiers based on those specified in [IETF RFC 4007].
`
``
`99`
`+
///
`
``
`100`
`+
/// It accepts addresses consisting of the following elements, in order:
`
``
`101`
`` +
/// - A left square bracket (`[`)
``
``
`102`
`+
/// - The [textual representation] of an IPv6 address
`
``
`103`
`` +
/// - _Optionally_, a percent sign (`%`) followed by the scope identifier
``
``
`104`
`+
/// encoded as a decimal integer
`
``
`105`
`` +
/// - A right square bracket (`]`)
``
``
`106`
`` +
/// - A colon (`:`)
``
``
`107`
`+
/// - The port, encoded as a decimal integer.
`
``
`108`
`+
///
`
``
`109`
`` +
/// For example, the string `[2001:db8::413]:443` represents a `SocketAddrV6`
``
``
`110`
`` +
/// with the address `2001:db8::413` and port `443`. The string
``
``
`111`
`` +
/// `[2001:db8::413%612]:443` represents the same address and port, with a
``
``
`112`
`` +
/// scope identifier of `612`.
``
``
`113`
`+
///
`
``
`114`
`+
/// Other formats are not accepted.
`
``
`115`
`+
///
`
``
`116`
`+
/// [IETF RFC 5952]: https://tools.ietf.org/html/rfc5952#section-6
`
``
`117`
`+
/// [IETF RFC 4007]: https://tools.ietf.org/html/rfc4007#section-11
`
``
`118`
`+
/// [textual representation]: Ipv6Addr#textual-representation
`
``
`119`
`+
///
`
`85`
`120`
`/// # Examples
`
`86`
`121`
`///
`
`87`
`122`
```` /// ```
`@@ -92,6 +127,10 @@ pub struct SocketAddrV4 {
`
92
127
`/// assert_eq!("[2001:db8::1]:8080".parse(), Ok(socket));
`
93
128
`/// assert_eq!(socket.ip(), &Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1));
`
94
129
`/// assert_eq!(socket.port(), 8080);
`
``
130
`+
///
`
``
131
`+
/// let mut with_scope = socket.clone();
`
``
132
`+
/// with_scope.set_scope_id(3);
`
``
133
`+
/// assert_eq!("[2001:db8::1%3]:8080".parse(), Ok(with_scope));
`
95
134
```` /// ```
````
96
135
`#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
`
97
136
`#[stable(feature = "rust1", since = "1.0.0")]
`