@@ -198,9 +198,10 @@ impl SocketAddr {
198198/// socket.set_ip(IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
199199/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
200200/// ```
201- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
202201#[ inline]
203- pub fn set_ip ( & mut self , new_ip : IpAddr ) {
202+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
203+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
204+ pub const fn set_ip ( & mut self , new_ip : IpAddr ) {
204205// `match (*self, new_ip)` would have us mutate a copy of self only to throw it away.
205206match ( self , new_ip) {
206207( & mut SocketAddr :: V4 ( ref mut a) , IpAddr :: V4 ( new_ip) ) => a. set_ip ( new_ip) ,
@@ -241,9 +242,10 @@ impl SocketAddr {
241242/// socket.set_port(1025);
242243/// assert_eq!(socket.port(), 1025);
243244/// ```
244- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
245245#[ inline]
246- pub fn set_port ( & mut self , new_port : u16 ) {
246+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
247+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
248+ pub const fn set_port ( & mut self , new_port : u16 ) {
247249match * self {
248250SocketAddr :: V4 ( ref mut a) => a. set_port ( new_port) ,
249251SocketAddr :: V6 ( ref mut a) => a. set_port ( new_port) ,
@@ -346,9 +348,10 @@ impl SocketAddrV4 {
346348/// socket.set_ip(Ipv4Addr::new(192, 168, 0, 1));
347349/// assert_eq!(socket.ip(), &Ipv4Addr::new(192, 168, 0, 1));
348350/// ```
349- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
350351#[ inline]
351- pub fn set_ip ( & mut self , new_ip : Ipv4Addr ) {
352+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
353+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
354+ pub const fn set_ip ( & mut self , new_ip : Ipv4Addr ) {
352355self . ip = new_ip;
353356}
354357
@@ -381,9 +384,10 @@ impl SocketAddrV4 {
381384/// socket.set_port(4242);
382385/// assert_eq!(socket.port(), 4242);
383386/// ```
384- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
385387#[ inline]
386- pub fn set_port ( & mut self , new_port : u16 ) {
388+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
389+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
390+ pub const fn set_port ( & mut self , new_port : u16 ) {
387391self . port = new_port;
388392}
389393}
@@ -442,9 +446,10 @@ impl SocketAddrV6 {
442446/// socket.set_ip(Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
443447/// assert_eq!(socket.ip(), &Ipv6Addr::new(76, 45, 0, 0, 0, 0, 0, 0));
444448/// ```
445- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
446449#[ inline]
447- pub fn set_ip ( & mut self , new_ip : Ipv6Addr ) {
450+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
451+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
452+ pub const fn set_ip ( & mut self , new_ip : Ipv6Addr ) {
448453self . ip = new_ip;
449454}
450455
@@ -477,9 +482,10 @@ impl SocketAddrV6 {
477482/// socket.set_port(4242);
478483/// assert_eq!(socket.port(), 4242);
479484/// ```
480- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
481485#[ inline]
482- pub fn set_port ( & mut self , new_port : u16 ) {
486+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
487+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
488+ pub const fn set_port ( & mut self , new_port : u16 ) {
483489self . port = new_port;
484490}
485491
@@ -524,9 +530,10 @@ impl SocketAddrV6 {
524530/// socket.set_flowinfo(56);
525531/// assert_eq!(socket.flowinfo(), 56);
526532/// ```
527- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
528533#[ inline]
529- pub fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
534+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
535+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
536+ pub const fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
530537self . flowinfo = new_flowinfo;
531538}
532539
@@ -566,9 +573,10 @@ impl SocketAddrV6 {
566573/// socket.set_scope_id(42);
567574/// assert_eq!(socket.scope_id(), 42);
568575/// ```
569- #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
570576#[ inline]
571- pub fn set_scope_id ( & mut self , new_scope_id : u32 ) {
577+ #[ stable( feature = "sockaddr_setters" , since = "1.9.0" ) ]
578+ #[ rustc_const_unstable( feature = "const_sockaddr_setters" , issue = "131714" ) ]
579+ pub const fn set_scope_id ( & mut self , new_scope_id : u32 ) {
572580self . scope_id = new_scope_id;
573581}
574582}
0 commit comments