-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 constructors of pinned Box
es
#97655
Improve documentation for constructors of pinned Box
es
#97655
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
@bors r+ rollup |
📌 Commit 6e2ac5d has been approved by |
…n-docs, r=thomcc Improve documentation for constructors of pinned `Box`es Adds a cross-references between `Box::pin` and `Box::into_pin` (and other related methods, i.e. the equivalent `From` implementation, and the unstable `pin_in` method), in particular now that `into_pin` [was stabilized](rust-lang#97397). The main goal is to further improve visibility of the fact that `Box<T> -> Pin<Box<T>>` conversion exits in the first place, and that `Box::pin(x)` is – essentially – just a convenience function for `Box::into_pin(Box::new(x))` The motivating context why I think this is important is even experienced Rust users overlooking the existence this kind of conversion, [e.g. in this thread on IRLO](https://internals.rust-lang.org/t/pre-rfc-function-variants/16732/7?u=steffahn); and also the fact that that discussion brought up that there would be a bunch of Box-construction methods "missing" such as e.g. methods with fallible allocation a la "`Box::try_pin`", and similar; while those are in fact *not* necessary, because you can use `Box::into_pin(Box::try_new(x)?)` instead. I have *not* included explicit mention of methods (e.g. `try_new`) in the docs of stable methods (e.g. `into_pin`). (Referring to unstable API in stable API docs would be bad style IMO.) Stable examples I have in mind with the statement "constructing a (pinned) Box in a different way than with `Box::new`" are things like cloning a `Box`, or `Box::from_raw`. If/when `try_new` would get stabilized, it would become a very good concrete example use-case of `Box::into_pin` IMO.
…askrgr Rollup of 5 pull requests Successful merges: - rust-lang#97502 (rustdoc: Add more test coverage) - rust-lang#97627 (update explicit impls error msg) - rust-lang#97640 (Fix wrong suggestion for adding where clauses) - rust-lang#97645 (don't use a `span_note` for ignored impls) - rust-lang#97655 (Improve documentation for constructors of pinned `Box`es) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Adds a cross-references between
Box::pin
andBox::into_pin
(and other related methods, i.e. the equivalentFrom
implementation, and the unstablepin_in
method), in particular now thatinto_pin
was stabilized. The main goal is to further improve visibility of the fact thatBox<T> -> Pin<Box<T>>
conversion exits in the first place, and thatBox::pin(x)
is – essentially – just a convenience function forBox::into_pin(Box::new(x))
The motivating context why I think this is important is even experienced Rust users overlooking the existence this kind of conversion, e.g. in this thread on IRLO; and also the fact that that discussion brought up that there would be a bunch of Box-construction methods "missing" such as e.g. methods with fallible allocation a la "
Box::try_pin
", and similar; while those are in fact not necessary, because you can useBox::into_pin(Box::try_new(x)?)
instead.I have not included explicit mention of methods (e.g.
try_new
) in the docs of stable methods (e.g.into_pin
). (Referring to unstable API in stable API docs would be bad style IMO.) Stable examples I have in mind with the statement "constructing a (pinned) Box in a different way than withBox::new
" are things like cloning aBox
, orBox::from_raw
. If/whentry_new
would get stabilized, it would become a very good concrete example use-case ofBox::into_pin
IMO.