@@ -295,7 +295,6 @@ impl IpAddr {
295295 /// assert_eq!(IpAddr::V4(Ipv4Addr::new(80, 9, 12, 3)).is_global(), true);
296296 /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1)).is_global(), true);
297297 /// ```
298- #[ rustc_const_unstable( feature = "const_ip" , issue = "76205" ) ]
299298 #[ unstable( feature = "ip" , issue = "27709" ) ]
300299 #[ must_use]
301300 #[ inline]
@@ -348,7 +347,6 @@ impl IpAddr {
348347 /// true
349348 /// );
350349 /// ```
351- #[ rustc_const_unstable( feature = "const_ip" , issue = "76205" ) ]
352350 #[ unstable( feature = "ip" , issue = "27709" ) ]
353351 #[ must_use]
354352 #[ inline]
@@ -600,6 +598,24 @@ impl Ipv4Addr {
600598 self . octets
601599 }
602600
601+ /// Creates an `Ipv4Addr` from a four element byte array.
602+ ///
603+ /// # Examples
604+ ///
605+ /// ```
606+ /// #![feature(ip_from)]
607+ /// use std::net::Ipv4Addr;
608+ ///
609+ /// let addr = Ipv4Addr::from_octets([13u8, 12u8, 11u8, 10u8]);
610+ /// assert_eq!(Ipv4Addr::new(13, 12, 11, 10), addr);
611+ /// ```
612+ #[ unstable( feature = "ip_from" , issue = "131360" ) ]
613+ #[ must_use]
614+ #[ inline]
615+ pub const fn from_octets ( octets : [ u8 ; 4 ] ) -> Ipv4Addr {
616+ Ipv4Addr { octets }
617+ }
618+
603619 /// Returns [`true`] for the special 'unspecified' address (`0.0.0.0`).
604620 ///
605621 /// This property is defined in _UNIX Network Programming, Second Edition_,
@@ -776,7 +792,6 @@ impl Ipv4Addr {
776792 ///
777793 /// // For a complete overview see the IANA IPv4 Special-Purpose Address Registry.
778794 /// ```
779- #[ rustc_const_unstable( feature = "const_ipv4" , issue = "76205" ) ]
780795 #[ unstable( feature = "ip" , issue = "27709" ) ]
781796 #[ must_use]
782797 #[ inline]
@@ -813,7 +828,6 @@ impl Ipv4Addr {
813828 /// assert_eq!(Ipv4Addr::new(100, 127, 255, 255).is_shared(), true);
814829 /// assert_eq!(Ipv4Addr::new(100, 128, 0, 0).is_shared(), false);
815830 /// ```
816- #[ rustc_const_unstable( feature = "const_ipv4" , issue = "76205" ) ]
817831 #[ unstable( feature = "ip" , issue = "27709" ) ]
818832 #[ must_use]
819833 #[ inline]
@@ -841,7 +855,6 @@ impl Ipv4Addr {
841855 /// assert_eq!(Ipv4Addr::new(198, 19, 255, 255).is_benchmarking(), true);
842856 /// assert_eq!(Ipv4Addr::new(198, 20, 0, 0).is_benchmarking(), false);
843857 /// ```
844- #[ rustc_const_unstable( feature = "const_ipv4" , issue = "76205" ) ]
845858 #[ unstable( feature = "ip" , issue = "27709" ) ]
846859 #[ must_use]
847860 #[ inline]
@@ -878,7 +891,6 @@ impl Ipv4Addr {
878891 /// // The broadcast address is not considered as reserved for future use by this implementation
879892 /// assert_eq!(Ipv4Addr::new(255, 255, 255, 255).is_reserved(), false);
880893 /// ```
881- #[ rustc_const_unstable( feature = "const_ipv4" , issue = "76205" ) ]
882894 #[ unstable( feature = "ip" , issue = "27709" ) ]
883895 #[ must_use]
884896 #[ inline]
@@ -1400,6 +1412,34 @@ impl Ipv6Addr {
14001412 ]
14011413 }
14021414
1415+ /// Creates an `Ipv6Addr` from an eight element 16-bit array.
1416+ ///
1417+ /// # Examples
1418+ ///
1419+ /// ```
1420+ /// #![feature(ip_from)]
1421+ /// use std::net::Ipv6Addr;
1422+ ///
1423+ /// let addr = Ipv6Addr::from_segments([
1424+ /// 0x20du16, 0x20cu16, 0x20bu16, 0x20au16,
1425+ /// 0x209u16, 0x208u16, 0x207u16, 0x206u16,
1426+ /// ]);
1427+ /// assert_eq!(
1428+ /// Ipv6Addr::new(
1429+ /// 0x20d, 0x20c, 0x20b, 0x20a,
1430+ /// 0x209, 0x208, 0x207, 0x206,
1431+ /// ),
1432+ /// addr
1433+ /// );
1434+ /// ```
1435+ #[ unstable( feature = "ip_from" , issue = "131360" ) ]
1436+ #[ must_use]
1437+ #[ inline]
1438+ pub const fn from_segments ( segments : [ u16 ; 8 ] ) -> Ipv6Addr {
1439+ let [ a, b, c, d, e, f, g, h] = segments;
1440+ Ipv6Addr :: new ( a, b, c, d, e, f, g, h)
1441+ }
1442+
14031443 /// Returns [`true`] for the special 'unspecified' address (`::`).
14041444 ///
14051445 /// This property is defined in [IETF RFC 4291].
@@ -1510,7 +1550,6 @@ impl Ipv6Addr {
15101550 ///
15111551 /// // For a complete overview see the IANA IPv6 Special-Purpose Address Registry.
15121552 /// ```
1513- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
15141553 #[ unstable( feature = "ip" , issue = "27709" ) ]
15151554 #[ must_use]
15161555 #[ inline]
@@ -1562,7 +1601,6 @@ impl Ipv6Addr {
15621601 /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(), false);
15631602 /// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
15641603 /// ```
1565- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
15661604 #[ unstable( feature = "ip" , issue = "27709" ) ]
15671605 #[ must_use]
15681606 #[ inline]
@@ -1591,7 +1629,6 @@ impl Ipv6Addr {
15911629 /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast(), true);
15921630 /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_unicast(), false);
15931631 /// ```
1594- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
15951632 #[ unstable( feature = "ip" , issue = "27709" ) ]
15961633 #[ must_use]
15971634 #[ inline]
@@ -1643,7 +1680,6 @@ impl Ipv6Addr {
16431680 /// assert_eq!(Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0).is_unicast_link_local(), true);
16441681 /// assert_eq!(Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
16451682 /// ```
1646- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
16471683 #[ unstable( feature = "ip" , issue = "27709" ) ]
16481684 #[ must_use]
16491685 #[ inline]
@@ -1668,7 +1704,6 @@ impl Ipv6Addr {
16681704 /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
16691705 /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
16701706 /// ```
1671- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
16721707 #[ unstable( feature = "ip" , issue = "27709" ) ]
16731708 #[ must_use]
16741709 #[ inline]
@@ -1729,7 +1764,6 @@ impl Ipv6Addr {
17291764 /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false);
17301765 /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(), true);
17311766 /// ```
1732- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
17331767 #[ unstable( feature = "ip" , issue = "27709" ) ]
17341768 #[ must_use]
17351769 #[ inline]
@@ -1758,7 +1792,6 @@ impl Ipv6Addr {
17581792 /// );
17591793 /// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None);
17601794 /// ```
1761- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
17621795 #[ unstable( feature = "ip" , issue = "27709" ) ]
17631796 #[ must_use]
17641797 #[ inline]
@@ -1818,7 +1851,6 @@ impl Ipv6Addr {
18181851 ///
18191852 /// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_ipv4_mapped(), false);
18201853 /// ```
1821- #[ rustc_const_unstable( feature = "const_ipv6" , issue = "76205" ) ]
18221854 #[ unstable( feature = "ip" , issue = "27709" ) ]
18231855 #[ must_use]
18241856 #[ inline]
@@ -1932,7 +1964,7 @@ impl Ipv6Addr {
19321964 /// use std::net::Ipv6Addr;
19331965 ///
19341966 /// assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(),
1935- /// [255 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
1967+ /// [0xff , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
19361968 /// ```
19371969 #[ rustc_const_stable( feature = "const_ip_32" , since = "1.32.0" ) ]
19381970 #[ stable( feature = "ipv6_to_octets" , since = "1.12.0" ) ]
@@ -1941,6 +1973,33 @@ impl Ipv6Addr {
19411973 pub const fn octets ( & self ) -> [ u8 ; 16 ] {
19421974 self . octets
19431975 }
1976+
1977+ /// Creates an `Ipv6Addr` from a sixteen element byte array.
1978+ ///
1979+ /// # Examples
1980+ ///
1981+ /// ```
1982+ /// #![feature(ip_from)]
1983+ /// use std::net::Ipv6Addr;
1984+ ///
1985+ /// let addr = Ipv6Addr::from_octets([
1986+ /// 0x19u8, 0x18u8, 0x17u8, 0x16u8, 0x15u8, 0x14u8, 0x13u8, 0x12u8,
1987+ /// 0x11u8, 0x10u8, 0x0fu8, 0x0eu8, 0x0du8, 0x0cu8, 0x0bu8, 0x0au8,
1988+ /// ]);
1989+ /// assert_eq!(
1990+ /// Ipv6Addr::new(
1991+ /// 0x1918, 0x1716, 0x1514, 0x1312,
1992+ /// 0x1110, 0x0f0e, 0x0d0c, 0x0b0a,
1993+ /// ),
1994+ /// addr
1995+ /// );
1996+ /// ```
1997+ #[ unstable( feature = "ip_from" , issue = "131360" ) ]
1998+ #[ must_use]
1999+ #[ inline]
2000+ pub const fn from_octets ( octets : [ u8 ; 16 ] ) -> Ipv6Addr {
2001+ Ipv6Addr { octets }
2002+ }
19442003}
19452004
19462005/// Writes an Ipv6Addr, conforming to the canonical style described by
@@ -2113,15 +2172,13 @@ impl From<[u8; 16]> for Ipv6Addr {
21132172 /// use std::net::Ipv6Addr;
21142173 ///
21152174 /// let addr = Ipv6Addr::from([
2116- /// 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8 ,
2117- /// 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8 ,
2175+ /// 0x19u8, 0x18u8, 0x17u8, 0x16u8, 0x15u8, 0x14u8, 0x13u8, 0x12u8 ,
2176+ /// 0x11u8, 0x10u8, 0x0fu8, 0x0eu8, 0x0du8, 0x0cu8, 0x0bu8, 0x0au8 ,
21182177 /// ]);
21192178 /// assert_eq!(
21202179 /// Ipv6Addr::new(
2121- /// 0x1918, 0x1716,
2122- /// 0x1514, 0x1312,
2123- /// 0x1110, 0x0f0e,
2124- /// 0x0d0c, 0x0b0a
2180+ /// 0x1918, 0x1716, 0x1514, 0x1312,
2181+ /// 0x1110, 0x0f0e, 0x0d0c, 0x0b0a,
21252182 /// ),
21262183 /// addr
21272184 /// );
@@ -2142,15 +2199,13 @@ impl From<[u16; 8]> for Ipv6Addr {
21422199 /// use std::net::Ipv6Addr;
21432200 ///
21442201 /// let addr = Ipv6Addr::from([
2145- /// 525u16, 524u16, 523u16, 522u16 ,
2146- /// 521u16, 520u16, 519u16, 518u16 ,
2202+ /// 0x20du16, 0x20cu16, 0x20bu16, 0x20au16 ,
2203+ /// 0x209u16, 0x208u16, 0x207u16, 0x206u16 ,
21472204 /// ]);
21482205 /// assert_eq!(
21492206 /// Ipv6Addr::new(
2150- /// 0x20d, 0x20c,
2151- /// 0x20b, 0x20a,
2152- /// 0x209, 0x208,
2153- /// 0x207, 0x206
2207+ /// 0x20d, 0x20c, 0x20b, 0x20a,
2208+ /// 0x209, 0x208, 0x207, 0x206,
21542209 /// ),
21552210 /// addr
21562211 /// );
@@ -2172,15 +2227,13 @@ impl From<[u8; 16]> for IpAddr {
21722227 /// use std::net::{IpAddr, Ipv6Addr};
21732228 ///
21742229 /// let addr = IpAddr::from([
2175- /// 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8 ,
2176- /// 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8 ,
2230+ /// 0x19u8, 0x18u8, 0x17u8, 0x16u8, 0x15u8, 0x14u8, 0x13u8, 0x12u8 ,
2231+ /// 0x11u8, 0x10u8, 0x0fu8, 0x0eu8, 0x0du8, 0x0cu8, 0x0bu8, 0x0au8 ,
21772232 /// ]);
21782233 /// assert_eq!(
21792234 /// IpAddr::V6(Ipv6Addr::new(
2180- /// 0x1918, 0x1716,
2181- /// 0x1514, 0x1312,
2182- /// 0x1110, 0x0f0e,
2183- /// 0x0d0c, 0x0b0a
2235+ /// 0x1918, 0x1716, 0x1514, 0x1312,
2236+ /// 0x1110, 0x0f0e, 0x0d0c, 0x0b0a,
21842237 /// )),
21852238 /// addr
21862239 /// );
@@ -2201,15 +2254,13 @@ impl From<[u16; 8]> for IpAddr {
22012254 /// use std::net::{IpAddr, Ipv6Addr};
22022255 ///
22032256 /// let addr = IpAddr::from([
2204- /// 525u16, 524u16, 523u16, 522u16 ,
2205- /// 521u16, 520u16, 519u16, 518u16 ,
2257+ /// 0x20du16, 0x20cu16, 0x20bu16, 0x20au16 ,
2258+ /// 0x209u16, 0x208u16, 0x207u16, 0x206u16 ,
22062259 /// ]);
22072260 /// assert_eq!(
22082261 /// IpAddr::V6(Ipv6Addr::new(
2209- /// 0x20d, 0x20c,
2210- /// 0x20b, 0x20a,
2211- /// 0x209, 0x208,
2212- /// 0x207, 0x206
2262+ /// 0x20d, 0x20c, 0x20b, 0x20a,
2263+ /// 0x209, 0x208, 0x207, 0x206,
22132264 /// )),
22142265 /// addr
22152266 /// );
0 commit comments