loopcell
Cell type(s) designed for read-modify-write-style loops, avoiding the manual write step.
Useful in complex event-handling services with multiple streams of input, and in particular it fits well into the iterator paradigm as long as you discard the produced values before the next iteration. In many ways, it can function as a "runtime version" of a lending iterator.
It also works well in combination with qcell
, ghost_cell
, and similar crates, if you use LoopCell
or LoopSyncCell
for the ownership control types.
Quick Example
This is a quick example illustrating how to use LoopCell
to create an iterator that reuses a shared buffer to process events. You can do something essentially identical with LoopSyncCell
, but it will work better in the case an access needs to be transferred across threads (which is common when implementing futures).
use ;
/// This illustrates the way this can be used as a pseudo-runtime-lending-iterator.
/// While this specific case could be implemented without the loopcell, in more complex
/// cases like having multiple iterators that all reuse the buffer or provide values that
/// reference the buffer, this is not possible because only one would be able to hold a
/// mutable reference at a time
/// Implementation detail that wipes a buffer with `clear()` on drop, but inherently preserves capacity.
;