Skip to content

Commit dad56f4

Browse files
author
Marco Conte
committed
const fn for SocketAddr::new, SocketAddrV4::new and SocketAddrV6::new
1 parent 3ed3b8b commit dad56f4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/libstd/net/addr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl SocketAddr {
125125
/// assert_eq!(socket.port(), 8080);
126126
/// ```
127127
#[stable(feature = "ip_addr", since = "1.7.0")]
128-
pub fn new(ip: IpAddr, port: u16) -> SocketAddr {
128+
pub const fn new(ip: IpAddr, port: u16) -> SocketAddr {
129129
match ip {
130130
IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)),
131131
IpAddr::V6(a) => SocketAddr::V6(SocketAddrV6::new(a, port, 0, 0)),
@@ -272,7 +272,7 @@ impl SocketAddrV4 {
272272
/// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
273273
/// ```
274274
#[stable(feature = "rust1", since = "1.0.0")]
275-
pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 {
275+
pub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 {
276276
SocketAddrV4 {
277277
inner: c::sockaddr_in {
278278
sin_family: c::AF_INET as c::sa_family_t,
@@ -364,7 +364,7 @@ impl SocketAddrV6 {
364364
/// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0);
365365
/// ```
366366
#[stable(feature = "rust1", since = "1.0.0")]
367-
pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 {
367+
pub const fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 {
368368
SocketAddrV6 {
369369
inner: c::sockaddr_in6 {
370370
sin6_family: c::AF_INET6 as c::sa_family_t,

0 commit comments

Comments
 (0)