Example for `std::sync::SyncView` is dubious
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Location (URL)
https://doc.rust-lang.org/nightly/std/sync/struct.SyncView.html#examples
Summary
The relevant portion of the example is:
assert_sync(State {
future: SyncView::new(async {
let cell = Cell::new(1);
let cell_ref = &cell;
other().await;
let value = cell_ref.get();
})
});
While it is true that this code compiles, it isn’t clear that it accomplishes anything useful, because the SyncView-wrapped async block is Sync but not Send, and thus State too is Sync but not Send. Thus, the only benefit of using SyncView here would be
- if the
struct Statehad other fields which are to be to be accessed from other threads, - and that access would have to occur while the future is not being polled.
These aspects are not in the example code nor discussed at all in the example’s accompanying text, and the example briefly misled me into thinking that SyncView could be used to produce a Send future of this sort (in the context of this URLO thread, “Borrow of owned !Sync type in async function”, which contains async {} code essentially identical to this example’s). I think that this example is significantly misleading, and it should ideally be replaced with a different one that illustrates producing Send + Sync from only Send, since Sync without Send is only very narrowly useful. If that is not possible, it should be expanded to at least vaguely gesture at making use of the Sync without Send condition.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the SyncView documentation example at std/sync/struct.SyncView.html#examples and review the shown State and async block alongside the issue's explanation of Send and Sync. Done means replacing or expanding the example and its accompanying text so the practical benefit of Sync without Send is accurately demonstrated and the misleading interpretation is removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100