66# Summary
77[ summary ] : #summary
88
9- Make the ` IpAddr ` , ` Ipv4Addr ` and ` Ipv6Addr ` types available in ` no_std `
9+ Make the ` IpAddr ` , ` Ipv4Addr ` , ` Ipv6Addr ` , ` SocketAddr ` , ` SocketAddrV4 ` ,
10+ ` SocketAddrV6 ` , ` Ipv6MulticastScope ` and ` AddrParseError ` types available in ` no_std `
1011contexts by moving them into a ` core::net ` module.
1112
1213# Motivation
@@ -21,40 +22,28 @@ dependencies which is in line with the definition of the core library.
2122# Guide-level explanation
2223[ guide-level-explanation ] : #guide-level-explanation
2324
24- The ` core::net::IpAddr ` , ` core::net::Ipv4Addr ` and ` core::net::Ipv6Addr ` types
25- are available in ` no_std ` contexts.
25+ The ` core::net::IpAddr ` , ` core::net::Ipv4Addr ` , ` core::net::Ipv6Addr ` ,
26+ ` core::net::SocketAddr ` , ` core::net::SocketAddrV4 ` , ` core::net::SocketAddrV6 ` ,
27+ ` core::net::Ipv6MulticastScope ` and ` core::net::AddrParseError ` types are
28+ available in ` no_std ` contexts.
2629
2730Library developers should use ` core::net ` to implement abstractions in order
2831for them to work in ` no_std ` contexts as well.
2932
3033# Reference-level explanation
3134[ reference-level-explanation ] : #reference-level-explanation
3235
33- Currently, the IP address types depend on their corresponding ` libc `
34- counterpart for their ` inner ` value.
36+ Since https://github.com/rust-lang/rust/pull/78802 has been merged, IP and
37+ socket address types are implemented in ideal Rust layout instead of wrapping
38+ their corresponding ` libc ` representation.
3539
36- IPv4 addresses are well-defined. [ IETF RFC 791] specifically states:
40+ Formatting for these types has also been adjusted in
41+ https://github.com/rust-lang/rust/pull/100625 and
42+ https://github.com/rust-lang/rust/pull/100640 in order to remove the dependency
43+ on ` std::io::Write ` .
3744
38- > Addresses are fixed length of four octets (32 bits).
39-
40- IPv6 addresses are well-defined. [ IETF RFC 4291] specifically states:
41-
42- > IPv6 addresses are 128-bit identifiers
43-
44- Since the size and representation of IPv4 and IPv6 addresses are well defined,
45- we can replace the ` inner ` value of ` Ipv4Addr ` with a ` [u8; 4] ` and the ` inner `
46- value of ` IPv6Addr ` with a ` [u8; 16] ` .
47-
48- The inner types ` [u8; 4] ` and ` [u8; 16] ` are expected to correspond to ` u32 `
49- and ` u128 ` in big-endian byte order. Currently, this is already ensured:
50-
51- - ` u32::to_be ` is used when constructing the corresponding ` libc ` type for
52- ` Ipv4Addr ` .
53- - The corresponding ` libc ` type for ` IPv6Addr ` is already represented as a
54- ` [u8; 16] ` internally on all platforms.
55-
56- [ IETF RFC 791 ] : https://tools.ietf.org/html/rfc791
57- [ IETF RFC 4291 ] : https://tools.ietf.org/html/rfc4291
45+ This means the types are now platform-agnostic, allowing them to be moved from
46+ ` std::net ` into ` core::net ` .
5847
5948# Drawbacks
6049[ drawbacks ] : #drawbacks
@@ -64,13 +53,10 @@ Moving the `std::net` types to `core::net` makes the core library less *minimal*
6453# Rationale and alternatives
6554[ rationale-and-alternatives ] : #rationale-and-alternatives
6655
67- - Given the size of IP addresses is well defined by IETF RFCs, there is no
68- inherent need to have these types depend on ` libc ` .
69-
7056- Eliminates the need to use different abstractions for ` no_std ` and ` std ` .
7157
7258- Alternatively, move these types into a library other than ` core ` , so they
73- can be used without ` std ` .
59+ can be used without ` std ` , and re-export them in ` std ` .
7460
7561# Prior art
7662[ prior-art ] : #prior-art
9177# Future possibilities
9278[ future-possibilities ] : #future-possibilities
9379
94- ` SocketAddr ` , ` SocketAddrV4 ` and ` SocketAddrV6 ` could also be moved in the
95- future.
80+ None.
0 commit comments