Skip to content

Commit fd7c616

Browse files
authored
Merge pull request #2832 from reitermarkus/core-net-types
RFC: Move `std::net::IpAddr` types into `core::net`.
2 parents c0a2cef + d73abe6 commit fd7c616

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

text/2832-core-net-types.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
- Feature Name: `core_net_types`
2+
- Start Date: 2019-12-06
3+
- RFC PR: [rust-lang/rfcs#2832](https://github.com/rust-lang/rfcs/pull/2832)
4+
- Rust Issue: [rust-lang/rust#108443](https://github.com/rust-lang/rust/issues/108443)
5+
6+
# Summary
7+
[summary]: #summary
8+
9+
Make the `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`,
10+
`SocketAddrV6`, `Ipv6MulticastScope` and `AddrParseError` types available in `no_std`
11+
contexts by moving them into a `core::net` module.
12+
13+
# Motivation
14+
[motivation]: #motivation
15+
16+
The motivation here is to provide common types for both `no_std` and `std`
17+
targets which in turn will ease the creation of libraries based around IP
18+
addresses. Embedded IoT development is one area where this will be beneficial.
19+
IP addresses are portable across all platforms and have no external
20+
dependencies which is in line with the definition of the core library.
21+
22+
# Guide-level explanation
23+
[guide-level-explanation]: #guide-level-explanation
24+
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.
29+
30+
Library developers should use `core::net` to implement abstractions in order
31+
for them to work in `no_std` contexts as well.
32+
33+
# Reference-level explanation
34+
[reference-level-explanation]: #reference-level-explanation
35+
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.
39+
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`.
44+
45+
This means the types are now platform-agnostic, allowing them to be moved from
46+
`std::net` into `core::net`.
47+
48+
# Drawbacks
49+
[drawbacks]: #drawbacks
50+
51+
Moving the `std::net` types to `core::net` makes the core library less *minimal*.
52+
53+
# Rationale and alternatives
54+
[rationale-and-alternatives]: #rationale-and-alternatives
55+
56+
- Eliminates the need to use different abstractions for `no_std` and `std`.
57+
58+
- Alternatively, move these types into a library other than `core`, so they
59+
can be used without `std`, and re-export them in `std`.
60+
61+
# Prior art
62+
[prior-art]: #prior-art
63+
64+
There was a prior discussion at
65+
66+
https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247/15
67+
68+
and an experimental branch from [@Nemo157](https://github.com/Nemo157) at
69+
70+
https://github.com/Nemo157/rust/tree/core-ip
71+
72+
# Unresolved questions
73+
[unresolved-questions]: #unresolved-questions
74+
75+
None.
76+
77+
# Future possibilities
78+
[future-possibilities]: #future-possibilities
79+
80+
Move the `ToSocketAddrs` trait to `core::net` as well. This depends on having `core::io::Result`.

0 commit comments

Comments
 (0)