Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 565c02d

Browse files
committedDec 6, 2019
RFC: Move std::net types into core:.net.
1 parent 809a988 commit 565c02d

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
 

‎text/0000-core-net-types.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
- Feature Name: `core_net_types`
2+
- Start Date: 2019-12-06
3+
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000)
4+
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)
5+
6+
# Summary
7+
[summary]: #summary
8+
9+
Make the `IpAddr`, `Ipv4Addr` and `Ipv6Addr` types available in `no_std`
10+
contexts by moving them into a `core::net` module.
11+
12+
# Motivation
13+
[motivation]: #motivation
14+
15+
The motivation here is to provide common types for both `no_std` and `std`
16+
targets which in turn will ease the creation of libraries based around IP
17+
addresses. Embedded IoT development is one area where this will be beneficial.
18+
IP addresses are portable across all platforms and have no external
19+
dependencies which is in line with the definition of the core library.
20+
21+
# Guide-level explanation
22+
[guide-level-explanation]: #guide-level-explanation
23+
24+
The `core::net::IpAddr`, `core::net::Ipv4Addr` and `core::net::Ipv6Addr` types
25+
are available in `no_std` contexts.
26+
27+
Library developers should use `core::net` to implement abstractions in order
28+
for them to work in `no_std` contexts as well.
29+
30+
# Reference-level explanation
31+
[reference-level-explanation]: #reference-level-explanation
32+
33+
Currently, the IP address types depend on their corresponding `libc`
34+
counterpart for ther `inner` value.
35+
36+
IPv4 addresses are well-defined. [IETF RFC 791] specifically states:
37+
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+
[IETF RFC 791]: https://tools.ietf.org/html/rfc791
49+
[IETF RFC 4291]: https://tools.ietf.org/html/rfc4291
50+
51+
# Drawbacks
52+
[drawbacks]: #drawbacks
53+
54+
Moving the `std::net` types to `core::net` makes the core library less *minimal*.
55+
56+
# Rationale and alternatives
57+
[rationale-and-alternatives]: #rationale-and-alternatives
58+
59+
- Given the size of IP addresses is well defined by IETF RFCs, there is no
60+
inherent need to have these types depend on `libc`.
61+
62+
- Eliminates the need to use different abstractions for `no_std` and `std`.
63+
64+
# Prior art
65+
[prior-art]: #prior-art
66+
67+
There was a prior discussion at
68+
69+
https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247/15
70+
71+
and an experimental branch from [@Nemo157](https://github.com/Nemo157) at
72+
73+
https://github.com/Nemo157/rust/tree/core-ip
74+
75+
# Unresolved questions
76+
[unresolved-questions]: #unresolved-questions
77+
78+
Should `SocketAddr`, `SocketAddrV4` and `SocketAddrV6` be moved to `core::net`
79+
as well?
80+
81+
# Future possibilities
82+
[future-possibilities]: #future-possibilities
83+
84+
Moving of `SocketAddr`, `SocketAddrV4` and `SocketAddrV6` could be done in the
85+
future depending on the unresolved question of whether this *should* be done.

0 commit comments

Comments
 (0)
Please sign in to comment.