Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRustdoc examples for mio::net methods #665
Comments
carllerche
added
the
help wanted
label
Aug 18, 2017
This comment has been minimized.
This comment has been minimized.
|
Hey, I would like to help out with the examples. Should they look like std::net::UdpSocket or be more detailed when possible? Taking // Sample 1
let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
let cloned = socket.try_clone();or should it look like: // Sample 2
let socket = UdpSocket::bind(&"127.0.0.1:7777".parse()?)?;
let cloned = socket.try_clone();
socket.set_broadcast(false)?;
assert_eq!(socket.broadcast()?, cloned.broadcast()?);Or something completely different? |
This comment has been minimized.
This comment has been minimized.
|
Ideally the examples would show why someone would want to use the method. Your sample 1 and sample 2 are both examples of how to use the method, which is not as valuable as why someone would want to use the method. Users looking at mio documentation can be expected to understand the syntax of how to invoke a method, so showing them how to invoke I would start by looking at crates that use mio, which of these methods they call as part of their realistic operation, and then use that to produce a short usage example that illustrates why the crate needs to call the method. |
This comment has been minimized.
This comment has been minimized.
|
@dtolnay Agreed! If you would be so kind as to answer another question. Should some examples repeat steps like: binding a socket, registering a // Like this line:
// Create a Poll and register the socket
// Now we are ready to use it
socket.whatever()
..... |
This comment has been minimized.
This comment has been minimized.
|
Great question. I would include as much surrounding steps as needed to make it clear why the example is doing what it is doing. If the repeated steps are just noise, it is okay to stub them out with a comment. If the repeated steps clarify where in the lifecycle of an application the important steps are taking place, in relation to where the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Yes it looks like you are going in the right direction. Feel free to make several small PRs as you work, we don't need all 100 examples in a single PR. I would focus on selecting examples that illustrate some detail of real-life usage of mio. So there can be simplifications and the occasional panic to keep things brief, but in terms of logic and control flow it should behave like something that a user of mio would want to write. I was thinking about this in the context of your |
lanedraex
referenced this issue
Nov 16, 2017
Merged
Added some examples fo mio::net::UdpSocket. #762
This comment has been minimized.
This comment has been minimized.
|
Closing due to inactivity. |
dtolnay commentedAug 18, 2017
Per the
C-EXAMPLEguideline.Keep in mind that the purpose of an example is not always to show how to use the item. Users can be expected to understand the syntax of how to invoke a method or match on an enum. Rather, an example is often intended to show why someone would want to use the item.