Skip to content

Commit 54ecca0

Browse files
committed
Auto merge of rust-lang#17885 - Wilfred:op_queue_docs, r=lnicola
minor: Add a doc comment for OpQueue Add an explanatory sentence and some sample code to help readers understand why this struct exists.
2 parents f96e296 + 5e058db commit 54ecca0

File tree

1 file changed

+20
-0
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src

1 file changed

+20
-0
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
44
pub(crate) type Cause = String;
55

6+
/// A single-item queue that allows callers to request an operation to
7+
/// be performed later.
8+
///
9+
/// ```
10+
/// let queue = OpQueue::default();
11+
///
12+
/// // Request work to be done.
13+
/// queue.request_op("user pushed a button", ());
14+
///
15+
/// // In a later iteration of the server loop, we start the work.
16+
/// if let Some((_cause, ())) = queue.should_start_op() {
17+
/// dbg!("Some slow operation here");
18+
/// }
19+
///
20+
/// // In an even later iteration of the server loop, we can see that the work
21+
/// // was completed.
22+
/// if !queue.op_in_progress() {
23+
/// dbg!("Work has been done!");
24+
/// }
25+
/// ```
626
#[derive(Debug)]
727
pub(crate) struct OpQueue<Args = (), Output = ()> {
828
op_requested: Option<(Cause, Args)>,

0 commit comments

Comments
 (0)