Skip to content

const fn for SocketAddr::new, SocketAddrV4::new and SocketAddrV6::new #67390

Closed
@gliderkite

Description

@gliderkite

This is a tracking issue for adding const fn to SocketAddr::new, SocketAddrV4::new and SocketAddrV6::new to be able to initialize the socket address at compile time, for example:

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6, SocketAddr};

const localhost_v4: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
const socket_v4: SocketAddrV4 = SocketAddrV4::new(localhost_v4, 80);
const socket_add_v4: SocketAddr = SocketAddr::new(IpAddr::V4(localhost_v4), 80);

const localhost_v6: Ipv6Addr = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1);
const socket_v6: SocketAddrV6 = SocketAddrV6::new(localhost_v6, 80, 0, 0);
const socket_add_v6: SocketAddr = SocketAddr::new(IpAddr::V6(localhost_v6), 80);

Open PR: #67315

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.S-blockedStatus: Blocked on something else such as an RFC or other implementation work.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions