-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a doctest for the std::string::as_string method. #19628
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
Add a doctest for the std::string::as_string method. #19628
Conversation
Sure thing! |
@steveklabnik Is "Examples" supposed to be the standard convention? I am noticing the occurrence of "Example" a number of places throughout the API docs. If so, I can try to update some of these other offending instances in a separate PR as well. |
We haven't officially made a convention because I haven't had the chance to write up the RFC, but you're correct that they're scattered. I wouldn't mind a PR updating them to all say "Examples," even if we eventually decide on a different convention, it's easier to change if they're all the same. |
60f916e
to
0beb7d8
Compare
Updated. |
Intrusive comment! :-) I'm worried about "Doctest". Providing examples in documentation is great, it's a good goal. Testing functions through it is not -- there are much better ways to do that using the testing infrastructure. So they should be useful examples first. The reason they are tested is just to make sure they continue to be up to date and correct. With this in mind, the example in the PR is not very instructive to the reader of the documentation. |
I should be constructive too, It's hard to find a good example truly, what do you think about this? use std::string::as_string;
fn stringconsumer(s: &String) {
assert_eq!(s, &"foo");
}
stringconsumer(&*as_string("foo")); |
0beb7d8
to
6dc9828
Compare
/// ``` | ||
/// use std::string::as_string; | ||
/// | ||
/// fn string_ref_consumer(s: &String) { |
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.
Taking a &String
is almost never what we want, can we make this a String
and
r=me with the updated example changes |
Change Example to Examples. Add a doctest that better demonstrates the utility of as_string. Update the doctest example to use String instead of &String.
6dc9828
to
de3fcee
Compare
Updated. |
Thank you so much! |
Friends, the example misses the point of The reason any example is contrieved is that there are no use cases I can think of, but what it used to be was that a certain interface needed |
don't ignore config values that fail to parse
No description provided.