|
62 | 62 | //! // Manually fetch the buffer update from the consumer interface |
63 | 63 | //! buf_output.update(); |
64 | 64 | //! |
65 | | -//! // Acquire read-only reference to the output buffer |
66 | | -//! let output = buf_output.peek_output_buffer(); |
| 65 | +//! // Acquire a read-only reference to the output buffer |
| 66 | +//! let output = buf_output.output_buffer(); |
67 | 67 | //! assert_eq!(*output, "Hello, "); |
68 | 68 | //! |
69 | | -//! // Or acquire mutable reference if necessary |
| 69 | +//! // Or acquire a mutable reference if necessary |
70 | 70 | //! let output_mut = buf_output.output_buffer_mut(); |
71 | 71 | //! |
72 | 72 | //! // Post-process the output value before use |
@@ -266,33 +266,17 @@ impl<T: Send> Input<T> { |
266 | 266 |
|
267 | 267 | /// Query the current value of the input buffer |
268 | 268 | /// |
269 | | - /// This is simply a read-only version of |
| 269 | + /// This is a read-only version of |
270 | 270 | /// [`input_buffer_mut()`](Input::input_buffer_mut). Please read the |
271 | 271 | /// documentation of that method for more information on the precautions |
272 | 272 | /// that need to be taken when accessing the input buffer in place. |
273 | | - fn peek_input_buffer(&self) -> &T { |
274 | | - // Access the input buffer directly |
| 273 | + pub fn input_buffer(&self) -> &T { |
| 274 | + // This is safe because the synchronization protocol ensures that we |
| 275 | + // have exclusive access to this buffer. |
275 | 276 | let input_ptr = self.shared.buffers[self.input_idx as usize].get(); |
276 | 277 | unsafe { &*input_ptr } |
277 | 278 | } |
278 | 279 |
|
279 | | - /// Access the input buffer directly |
280 | | - /// |
281 | | - /// This is, for now, a deprecated alias to |
282 | | - /// [`input_buffer_mut()`](Input::input_buffer_mut). Please use this method |
283 | | - /// instead. |
284 | | - /// |
285 | | - /// In a future major release of this crate, `input_buffer()` will |
286 | | - /// undergo a breaking change to instead provide read-only access. |
287 | | - /// |
288 | | - /// The aim of this process is to eventually migrate towards the standard |
289 | | - /// `accessor()`/`accessor_mut()` method naming convention that most Rust |
290 | | - /// libraries follow. |
291 | | - #[deprecated = "Please use input_buffer_mut() instead"] |
292 | | - pub fn input_buffer(&mut self) -> &mut T { |
293 | | - self.input_buffer_mut() |
294 | | - } |
295 | | - |
296 | 280 | /// Access the input buffer directly |
297 | 281 | /// |
298 | 282 | /// This advanced interface allows you to update the input buffer in place, |
@@ -398,7 +382,7 @@ impl<T: Send> Deref for InputPublishGuard<'_, T> { |
398 | 382 | type Target = T; |
399 | 383 |
|
400 | 384 | fn deref(&self) -> &T { |
401 | | - self.reference.peek_input_buffer() |
| 385 | + self.reference.input_buffer() |
402 | 386 | } |
403 | 387 | } |
404 | 388 |
|
@@ -467,44 +451,32 @@ impl<T: Send> Output<T> { |
467 | 451 |
|
468 | 452 | /// Query the current value of the output buffer |
469 | 453 | /// |
470 | | - /// This is simply a read-only version of |
| 454 | + /// This is a deprecated compatibility alias to |
| 455 | + /// [`output_buffer()`](Self::output_buffer). Please use that method |
| 456 | + /// instead, as `peek_output_buffer()` is scheduled for removal in the next |
| 457 | + /// major release of `triple-buffer`. |
| 458 | + #[deprecated = "Please use output_buffer() instead"] |
| 459 | + pub fn peek_output_buffer(&self) -> &T { |
| 460 | + self.output_buffer() |
| 461 | + } |
| 462 | + |
| 463 | + /// Query the current value of the output buffer |
| 464 | + /// |
| 465 | + /// This is a read-only version of |
471 | 466 | /// [`output_buffer_mut()`](Output::output_buffer_mut). Please read the |
472 | 467 | /// documentation of that method for more information on the precautions |
473 | 468 | /// that need to be taken when accessing the output buffer in place. |
474 | 469 | /// |
475 | 470 | /// In particular, remember that this method does not update the output |
476 | 471 | /// buffer automatically. You need to call [`update()`](Output::update) in |
477 | 472 | /// order to fetch buffer updates from the producer. |
478 | | - pub fn peek_output_buffer(&self) -> &T { |
479 | | - // Access the output buffer directly |
| 473 | + pub fn output_buffer(&self) -> &T { |
| 474 | + // This is safe because the synchronization protocol ensures that we |
| 475 | + // have exclusive access to this buffer. |
480 | 476 | let output_ptr = self.shared.buffers[self.output_idx as usize].get(); |
481 | 477 | unsafe { &*output_ptr } |
482 | 478 | } |
483 | 479 |
|
484 | | - /// Access the input buffer directly |
485 | | - /// |
486 | | - /// This is, for now, a deprecated alias to [`output_buffer_mut()`]. Please |
487 | | - /// use this method instead. |
488 | | - /// |
489 | | - /// In a future major release of this crate, `output_buffer()` will undergo |
490 | | - /// a breaking change to instead provide read-only access, like |
491 | | - /// [`peek_output_buffer()`] currently does. At that point, |
492 | | - /// [`peek_output_buffer()`] will be deprecated. |
493 | | - /// |
494 | | - /// Finally, in a later major release [`peek_output_buffer()`] will be |
495 | | - /// removed. |
496 | | - /// |
497 | | - /// The aim of this process is to eventually migrate towards the standard |
498 | | - /// `accessor()`/`accessor_mut()` method naming convention that most Rust |
499 | | - /// libraries follow. |
500 | | - /// |
501 | | - /// [`output_buffer_mut()`]: Output::output_buffer_mut |
502 | | - /// [`peek_output_buffer()`]: Output::peek_output_buffer |
503 | | - #[deprecated = "Please use output_buffer_mut() instead"] |
504 | | - pub fn output_buffer(&mut self) -> &mut T { |
505 | | - self.output_buffer_mut() |
506 | | - } |
507 | | - |
508 | 480 | /// Access the output buffer directly |
509 | 481 | /// |
510 | 482 | /// This advanced interface allows you to modify the contents of the output |
@@ -1169,7 +1141,7 @@ mod tests { |
1169 | 1141 | move || { |
1170 | 1142 | let mut last_value = 0usize; |
1171 | 1143 | while last_value < TEST_WRITE_COUNT { |
1172 | | - match buf_output.peek_output_buffer().get() { |
| 1144 | + match buf_output.output_buffer().get() { |
1173 | 1145 | Racey::Consistent(new_value) => { |
1174 | 1146 | assert!((new_value >= last_value) && (new_value <= TEST_WRITE_COUNT)); |
1175 | 1147 | last_value = new_value; |
@@ -1240,7 +1212,7 @@ mod tests { |
1240 | 1212 |
|
1241 | 1213 | // Check that the output_buffer query works in the initial state |
1242 | 1214 | assert_eq!( |
1243 | | - as_ptr(&buf.output.peek_output_buffer()), |
| 1215 | + as_ptr(&buf.output.output_buffer()), |
1244 | 1216 | buf.output.shared.buffers[buf.output.output_idx as usize].get() |
1245 | 1217 | ); |
1246 | 1218 | assert_eq!(*buf, initial_buf); |
|
0 commit comments