Struct dubble::DoubleBuffered[][src]

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.

Methods

impl<T: Clone> DoubleBuffered<T>
[src]

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);
// my_buf.write(wb);

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.

Trait Implementations

impl<T: Clone> Deref for DoubleBuffered<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T: Clone> DerefMut for DoubleBuffered<T>
[src]

Mutably dereferences the value.

impl<T: Default + Clone> Default for DoubleBuffered<T>
[src]

Use the default constructor for the type.

impl<I, T: Index<I> + Clone> Index<I> for DoubleBuffered<T>
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<I, T: IndexMut<I> + Clone> IndexMut<I> for DoubleBuffered<T>
[src]

Performs the mutable indexing (container[index]) operation.

Auto Trait Implementations

impl<T> Send for DoubleBuffered<T> where
    T: Send

impl<T> Sync for DoubleBuffered<T> where
    T: Sync