6
6
# Summary
7
7
[ summary ] : #summary
8
8
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 `
10
11
contexts by moving them into a ` core::net ` module.
11
12
12
13
# Motivation
@@ -21,40 +22,28 @@ dependencies which is in line with the definition of the core library.
21
22
# Guide-level explanation
22
23
[ guide-level-explanation ] : #guide-level-explanation
23
24
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.
26
29
27
30
Library developers should use ` core::net ` to implement abstractions in order
28
31
for them to work in ` no_std ` contexts as well.
29
32
30
33
# Reference-level explanation
31
34
[ reference-level-explanation ] : #reference-level-explanation
32
35
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.
35
39
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 ` .
37
44
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 ` .
58
47
59
48
# Drawbacks
60
49
[ drawbacks ] : #drawbacks
@@ -64,13 +53,10 @@ Moving the `std::net` types to `core::net` makes the core library less *minimal*
64
53
# Rationale and alternatives
65
54
[ rationale-and-alternatives ] : #rationale-and-alternatives
66
55
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
-
70
56
- Eliminates the need to use different abstractions for ` no_std ` and ` std ` .
71
57
72
58
- 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 ` .
74
60
75
61
# Prior art
76
62
[ prior-art ] : #prior-art
91
77
# Future possibilities
92
78
[ future-possibilities ] : #future-possibilities
93
79
94
- ` SocketAddr ` , ` SocketAddrV4 ` and ` SocketAddrV6 ` could also be moved in the
95
- future.
80
+ None.
0 commit comments