-
Notifications
You must be signed in to change notification settings - Fork 13k
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 documentation for Fn*
traits
#35810
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
/// | ||
/// The `Fn` trait governs the invocation operator `()`. Closures automatically | ||
/// implement this trait, which allows them to be invoked. Note, however, that | ||
/// `Fn` takes an immutable reference to the argument. To take an immutable |
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 think you want to write "to take an mutable"
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 do indeed. Thank you! I'll go ahead and refactor these docs a bit now.
I've added some more documentation, more for form then contact at this point because I don't quite understand these traits yet. |
@@ -64,6 +64,50 @@ | |||
//! | |||
//! See the documentation for each trait for a minimum implementation that | |||
//! prints something to the screen. | |||
//! | |||
//! The `Fn`, `FnMut`, and `FnOnce` traits are implemented by types that can be |
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.
these should link to the traits
a5c99da
to
cd0676c
Compare
This is now approaching a serious attempt at contribution. :P |
Nice! Seems good to me but I'll let @steveklabnik handles it. |
Actually, I believe my |
Okay, fixed. |
☔ The latest upstream changes (presumably #35857) made this pull request unmergeable. Please resolve the merge conflicts. |
b4c39df
to
71b09eb
Compare
//! func(1) | ||
//! } | ||
//! | ||
//! let double = |x| x + x; |
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.
Perhaps x * 2
? I associate doubling with multiplication (though the two are clearly equivalent).
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.
Done. :)
I can think of a few things we may want to accomplish with the documentation of the `Fn`, `FnMut`, and `FnOnce` traits: - the relationship between these traits and the closures that implement them - examples of non-closure implementations - the relationship between these traits and Rust's ownership semantics add module-level documentation for `Fn*` traits Describe how `Fn*` traits, closure types, and ownership semantics are linked, and provide examples of higher-level functions that take `Fn*`s. more examples for `Fn*` traits create correct (though not yet elegant) examples for `FnMut` and `FnOnce` add trait links to module-level documentation third time's a charm! argument -> capture for trait documentation This wording will need to be supported with better examples for capturing eventually. correct `FnOnce` example I also fixed some of the trait wording here to make the concept of capturing clearer; though that still needs more work. replace `x + x` with `x * 2` for `fn double`
44a27df
to
67b9cd3
Compare
@bors: r+ rollup thanks a lot! |
📌 Commit 67b9cd3 has been approved by |
⌛ Testing commit 67b9cd3 with merge 78f057b... |
💔 Test failed - auto-mac-64-opt-rustbuild |
@bors retry |
…steveklabnik improve documentation for `Fn*` traits This PR is not yet a serious attempt at contribution. Rather, I'm opening this for discussion. I can think of a few things we may want to accomplish with the documentation of the `Fn`, `FnMut`, and `FnOnce` traits: - the relationship between these traits and the closures that implement them - examples of non-closure implementations - the relationship between these traits and Rust's ownership semantics
This PR is not yet a serious attempt at contribution. Rather, I'm opening this for discussion. I can think of a few things we may want to accomplish with the documentation of the
Fn
,FnMut
, andFnOnce
traits: