about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-14 05:13:44 +0000
committerbors <bors@rust-lang.org>2024-08-14 05:13:44 +0000
commit54ecca078f4061325d3b230c7d7361c48b3d2ba8 (patch)
tree9ae714e284a64735caed87cc98422e621ab4d7f2 /src
parentf96e296927cc0c6e9dd611edb943f6349001eca5 (diff)
parent5e058db6828acf4df9f765f59522fc0dbe19ae60 (diff)
downloadrust-54ecca078f4061325d3b230c7d7361c48b3d2ba8.tar.gz
rust-54ecca078f4061325d3b230c7d7361c48b3d2ba8.zip
Auto merge of #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.
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs
index 99f9e9829c9..eab97338724 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/op_queue.rs
@@ -3,6 +3,26 @@
 
 pub(crate) type Cause = String;
 
+/// A single-item queue that allows callers to request an operation to
+/// be performed later.
+///
+/// ```
+/// let queue = OpQueue::default();
+///
+/// // Request work to be done.
+/// queue.request_op("user pushed a button", ());
+///
+/// // In a later iteration of the server loop, we start the work.
+/// if let Some((_cause, ())) = queue.should_start_op() {
+///     dbg!("Some slow operation here");
+/// }
+///
+/// // In an even later iteration of the server loop, we can see that the work
+/// // was completed.
+/// if !queue.op_in_progress() {
+///     dbg!("Work has been done!");
+/// }
+/// ```
 #[derive(Debug)]
 pub(crate) struct OpQueue<Args = (), Output = ()> {
     op_requested: Option<(Cause, Args)>,