pub struct DoubleBuffered<T: Clone> { /* fields omitted */ }
Represents something that is double-buffered. The type being buffered must
be Clone
, so that the read buffer can be updated with the contents of the
write buffer during the update.
See the module-level documentation for more information.
Initialises the double-buffer with the value. Both buffers are initialised
with the same value.
Uses constructor
to construct each buffer. It's handy to pass things
like Vec::new
into here. DoubleBuffered
also implements default
if the wrapped type does, so you could also do
DoubleBuffered<Vec<T>>::default()
Returns an immutable reference to the read buffer.
Returns a mutable reference to the write buffer.
Note that changes made through this reference will not be reflected
until after update
is called.
This might seem a little weird; "why not just go my_buf.write(stuff)
"?.
The reason is so that you can update the elements of a collection without
having to build a clone of the collection. For example:
let mut my_buf: DoubleBuffered<Vec<i32>> = DoubleBuffered::default();
let mut wb = my_buf.write();
wb.push(4);
Compared to the other potential form:
let mut wb = my_buf.read().clone();
wb.push(5);
Notice that you have to create a copy and modify it.
Copies the write buffer into the read buffer.
Writes the value to the write buffer, and then immediately updates the
read buffer.
Returns the read buffer. This does not update the read buffer with the
contents of the write buffer beforehand. You could think of this like
"quit without saving" in a word processor.
Returns the write buffer.
The resulting type after dereferencing.
Mutably dereferences the value.
Use the default constructor for the type.
The returned type after indexing.
Performs the indexing (container[index]
) operation.
Performs the mutable indexing (container[index]
) operation.