Skip to content

Tracking Issue for #![feature(const_socketaddr)] #82485

@CDirkx

Description

@CDirkx
Contributor

Feature gate: #![feature(const_socketaddr)]

This is a tracking issue for constifying methods of std::net::SocketAddr, SocketAddrV4 and SocketAddrV6.

Public API

// std::net

impl SocketAddr {
   pub const fn new(ip: IpAddr, port: u16) -> Self;
    pub const fn ip(&self) -> IpAddr;
    pub const fn port(&self) -> u16;
    pub const fn is_ipv4(&self) -> bool;
    pub const fn is_ipv6(&self) -> bool;
}

impl SocketAddrV4 {
    pub const fn new(ip: Ipv4Addr, port: u16) -> Self;
    pub const fn ip(&self) -> IpAddr;
    pub const fn port(&self) -> u16;
}

impl SocketAddrV6 {
    pub const fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> Self;
    pub const fn ip(&self) -> IpAddr;
    pub const fn port(&self) -> u16;
    pub const fn flowinfo(&self) -> u32;
    pub const fn scope_id(&self) -> u32;
}

Steps / History

Unresolved Questions

The methods new on all of the address could potentially also be made const, however there are two complications: getting the inner C representation of an IP address, and adding trailing zero bytes on windows. Resolved by #78802

Activity

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Feb 24, 2021
CDirkx

CDirkx commented on Mar 1, 2021

@CDirkx
Author
added 2 commits that reference this issue on Apr 2, 2021
added a commit that references this issue on Apr 3, 2021
a1ien

a1ien commented on Jan 17, 2022

@a1ien

What about SocketAddr::new? If we make const ip, port and and so on how we create const SocketAddr it self

PS. oh now read Unresolved Questions :) Without const new it's seams no point to make other method const

faern

faern commented on Jun 23, 2022

@faern
Contributor

This feature gate is soon also used for the unstably constified methods SocketAddr::new, SocketAddrV4::new, SocketAddrV6::new if #78802 is merged.

maxwase

maxwase commented on Nov 10, 2022

@maxwase
Contributor

I guess there are no blockers for this stabilization?

faern

faern commented on Nov 10, 2022

@faern
Contributor

Probably not. Try submitting a stabilization PR.

EDIT: I'm on it.

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @a1ien@RalfJung@faern@m-ou-se@dtolnay

      Issue actions

        Tracking Issue for `#![feature(const_socketaddr)]` · Issue #82485 · rust-lang/rust