local-ip-address icon indicating copy to clipboard operation
local-ip-address copied to clipboard

Why local_ip() return IpAddr?

Open amateomi opened this issue 1 year ago • 1 comments

According to documentation, local_ip() function retrieves the local IPv4 address (and local_ipv6() retrieves the local IPv6 address), but why inside return type is general IpAddr enum instead of Ipv4Addr and Ipv6Addr? I think it's confusing and inconvenient for user.

amateomi avatar Mar 03 '24 16:03 amateomi

According to documentation, local_ip() function retrieves the local IPv4 address (and local_ipv6() retrieves the local IPv6 address), but why inside return type is general IpAddr enum instead of Ipv4Addr and Ipv6Addr? I think it's confusing and inconvenient for user.

Hi @amateomi! Thanks for openning this issue!

This is because at first, only IPv4 Addresses were used. Then, with changes and contributions the need of a specific IP version came up.

It it was for me today, I would introduce these funcions as follows:

  • local_ip() -> IpAddr
  • local_ipv4() -> Ipv4Addr
  • local_ipv6() -> Ipv6Addr

If we want to go this way, we would have to revisit each OS impl and also draft a major release (thus dropping backwards).

LeoBorai avatar Mar 03 '24 19:03 LeoBorai