-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve std::net docs #40838
Improve std::net docs #40838
Conversation
Part of #29363 In the section about the default implementations of ToSocketAddrs, I moved the bulletpoint of SocketAddrV4 & SocketAddrV6 to the one stating that SocketAddr is constructed trivially, as this is what's actually the case
Additionally changed the summary sentence to be more consistent with most of the other FromStr implementations' error types.
Part of #29363 Expanded top-level documentation & linked to relevant IETF RFCs. Added a bunch of links (to true/false/Ipv4Addr/etc.) throughout the docs.
Relative links in trait methods don't resolve in e.g. std/primitive.tuple.html :(
…AddrV6} docs Part of #29363 Changed summary sentences of SocketAddr and IpAddr for consistency Linked to SocketAddrV4 and SocketAddrV6 from SocketAddr, moving explaination there Expanded top-level docs for SocketAddrV4 and SocketAddrV6, linking to some relevant IETF RFCs, and linking back to SocketAddr Changed some of the method summaries to third person as per RFC 1574; added links to IETF RFCs where appropriate
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
r? @steveklabnik |
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub enum SocketAddr { | ||
/// An IPv4 socket address which is a (ip, port) combination. | ||
/// An IPv4 socket address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those (like me) who aren't much into network, the original sentence made more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably address this by mentioning this in SocketAddr
's top-level docs again, since it's also (mostly) true for the V6 variant (unless someone has a better solution)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it's fine; it's a summary line, not a full explanation.
#[stable(feature = "rust1", since = "1.0.0")] | ||
V4(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV4), | ||
/// An IPv6 socket address. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
V6(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV6), | ||
} | ||
|
||
/// An IPv4 socket address which is a (ip, port) combination. | ||
/// An IPv4 socket address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this small introduction better but I think the removed part should be put somewhere under.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It being a combination of IP address and port is already stated in the next sentence. Should I make that more explicit?
src/libstd/net/addr.rs
Outdated
/// Returns true if the IP in this `SocketAddr` is a valid IPv4 address, | ||
/// false if it's a valid IPv6 address. | ||
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an | ||
/// [IPv4 address] and [`false`] if it's an [IPv6 address]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if "or false" wouldn't be better than "and false". Anyone has a thought on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put a comma before the "and" (but keep the "and")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One formulation I thought about was , `false` otherwise
, maybe that's better?
src/libstd/net/addr.rs
Outdated
/// Returns true if the IP in this `SocketAddr` is a valid IPv6 address, | ||
/// false if it's a valid IPv4 address. | ||
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an | ||
/// [IPv6 address] and [`false`] if it's an [IPv4 address]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
Except for the few (very) little nits I mentionned, it's awesome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
src/libstd/net/addr.rs
Outdated
/// Returns true if the IP in this `SocketAddr` is a valid IPv4 address, | ||
/// false if it's a valid IPv6 address. | ||
/// Returns [`true`] if the [IP address] in this `SocketAddr` is an | ||
/// [IPv4 address] and [`false`] if it's an [IPv6 address]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put a comma before the "and" (but keep the "and")
src/libstd/net/addr.rs
Outdated
/// corresponding to the `sin6_flowinfo` field in C. | ||
/// Returns the flow information associated with this address. | ||
/// | ||
/// This information corresponds to the `sin6_flowinfo` field in C, as specified in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"in C" → "in C's netinet/in.h
"
src/libstd/net/addr.rs
Outdated
@@ -632,7 +746,9 @@ pub trait ToSocketAddrs { | |||
/// | |||
/// # Errors | |||
/// | |||
/// Any errors encountered during resolution will be returned as an `Err`. | |||
/// Any errors encountered during resolution will be returned as an [`Err`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is obvious from the function signature with Result
that it returns an Err
on error… Or you would have added a "Panics" section instead 😉 Maybe instead mention which Err variants it will return? Apparently one/some of std::io::Error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked around and it seems like the std::io::ErrorKind
s that might (commonly) come in the provided implementations are InvalidInput
, PermissionDenied
, and NotFound
.
I will add this instance with this PR, but this is kind of an issue in general throughout the docs (#40322) and out of scope for what I wanted to achieve with this PR. Thanks for the pointer tho, this does sound rather silly!
(Sidenote: I will have to test this myself, but it seems like from Windows' decode_error_kind
implementation that this might return an io:Error
with ErrorKind::Other
more often then it should/could on Windows??)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yes, agreed with both: this does feel a little redundant right now, but also, we do want to start describing which errors actually can happen.
You could also just remove this section for the purposes of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed some bona fide errors here and there, will correct them later
src/libstd/net/mod.rs
Outdated
//! [`SocketAddrV6`]: ../../std/net/struct.SocketAddrV6.html | ||
//! [`TcpListener`]: ../../std/net/struct.TcpListener.html | ||
//! [`TcpStream`]: ../../std/net/struct.TcpStream.html | ||
//! [`ToSocketAddr`]: ../../std/net/trait.ToSocketAddr.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ../../std/net/trait.ToSocketAddrs.html
(cought by linkchecker)
src/libstd/net/mod.rs
Outdated
//! [`Ipv6Addr`] are respectively IPv4 and IPv6 addresses | ||
//! * [`SocketAddr`] represents socket addresses of either IPv4 or IPv6; [`SocketAddrV4`] | ||
//! and [`SocketAddrV6`] are respectively IPv4 and IPv6 socket addresses | ||
//! * [`ToSocketAddr`] is a trait that used for generic address resolution interacting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a "when" before "interacting"
/// | ||
/// # Examples | ||
/// | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is missing the closing ```
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful PR. Thanks so much!
src/libstd/net/addr.rs
Outdated
@@ -632,7 +746,9 @@ pub trait ToSocketAddrs { | |||
/// | |||
/// # Errors | |||
/// | |||
/// Any errors encountered during resolution will be returned as an `Err`. | |||
/// Any errors encountered during resolution will be returned as an [`Err`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yes, agreed with both: this does feel a little redundant right now, but also, we do want to start describing which errors actually can happen.
You could also just remove this section for the purposes of this PR.
* Fixed spelling ToSocketAddr -> ToSocketAddrs in module docs (which also fixes a link) * Added missing "when" before "interacting" in module docs * Changed SocketAddr's top-level docs to explicitly state what socket addresses consist of, making them more consistent with SocketAddrV4's and SocketAddrV6's docs * Changed "in C" -> "in C's `netinet/in.h`" * Changed wording in is_ipv4/is_ipv6 methods to ", `false` otherwise" * Add missing closing ` ``` ` in Ipv6Addr's examples * Removed "Errors" section in ToSocketAddrs' to_socket_addrs method as it was rather redundant
Addressed requested changes; see commit description for more details. |
Looks great to me! |
Since everyone approved, I'll start the merge process. Don't hesitate to r- if there is anything wrong. @bors: r+ rollup |
📌 Commit b8cbc5d has been approved by |
…omez Improve std::net docs Fixes rust-lang#29363 Summary: * Added a _lot_ of missing links, both to other types/methods and to IETF RFCs, and changed occurences of just "RFC" to "IETF RFC" * Expanded a bunch of top-level docs, specifically the module docs & the docs for `TcpListener`, `TcpStream`, `UdpSocket`, `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, * Expanded method docs for `SocketAddrV6`, `AddrParseError`, * Various edits for clarity, consistency, and accuracy See the commit descriptions for more detail. Things not done quite as laid out in the task list in rust-lang#29363: * `AddrParseError` still doesn't have examples, but I wasn't quite sure how to do them; other `FromStr` error types don't have any, either * I didn't link to an IETF RFC in `IpAddr`, but in `Ipv4Addr` and `Ipv6Addr` and linked tho those from `IpAddr`; this seems more appropriate to me * Similarly, I didn't really exand `SocketAddr`'s docs, but elaborated on `SocketAddrV4` and `SocketAddrV6`'s and linked to them from `SocketAddr` Theres definitely still room for improvement, but this should be a good first effort 😄
…omez Improve std::net docs Fixes rust-lang#29363 Summary: * Added a _lot_ of missing links, both to other types/methods and to IETF RFCs, and changed occurences of just "RFC" to "IETF RFC" * Expanded a bunch of top-level docs, specifically the module docs & the docs for `TcpListener`, `TcpStream`, `UdpSocket`, `IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, `SocketAddrV6`, * Expanded method docs for `SocketAddrV6`, `AddrParseError`, * Various edits for clarity, consistency, and accuracy See the commit descriptions for more detail. Things not done quite as laid out in the task list in rust-lang#29363: * `AddrParseError` still doesn't have examples, but I wasn't quite sure how to do them; other `FromStr` error types don't have any, either * I didn't link to an IETF RFC in `IpAddr`, but in `Ipv4Addr` and `Ipv6Addr` and linked tho those from `IpAddr`; this seems more appropriate to me * Similarly, I didn't really exand `SocketAddr`'s docs, but elaborated on `SocketAddrV4` and `SocketAddrV6`'s and linked to them from `SocketAddr` Theres definitely still room for improvement, but this should be a good first effort 😄
Fixes #29363
Summary:
TcpListener
,TcpStream
,UdpSocket
,IpAddr
,Ipv4Addr
,Ipv6Addr
,SocketAddr
,SocketAddrV4
,SocketAddrV6
,SocketAddrV6
,AddrParseError
,See the commit descriptions for more detail.
Things not done quite as laid out in the task list in #29363:
AddrParseError
still doesn't have examples, but I wasn't quite sure how to do them; otherFromStr
error types don't have any, eitherIpAddr
, but inIpv4Addr
andIpv6Addr
and linked tho those fromIpAddr
; this seems more appropriate to meSocketAddr
's docs, but elaborated onSocketAddrV4
andSocketAddrV6
's and linked to them fromSocketAddr
Theres definitely still room for improvement, but this should be a good first effort 😄