Struct sb_rust_library::update_buffer::UpdateBuffer[][src]

pub struct UpdateBuffer<T: Sized + Clone> { /* fields omitted */ }

Data structure which uses a buffer to perform buffered updates to data.

Explicitly, this structure keeps two copies of some generic data type, which can be accesssed by the methods old() and new(). The idea is that during the course of an algorithm, you read from the old values and write to the new values. Then after the step is finished, you call swap_buffer such that old now points towards new.

Since you read from old and write to new, the methods old() and new() return &T and &mut T respectively. This prevents any borrowing conflicts.

This data structure provides three main benefits:

  1. It makes the update step in an algorithm clean and explicit.
  2. It allocates all memory used at initialization so the algorithm doesn't have to allocate memory in each step.
  3. It plays well with the rust borrow checker.

Implementations

impl<T: Sized + Clone> UpdateBuffer<T>[src]

pub fn from(initial: T) -> UpdateBuffer<T>[src]

Creates a new update buffer with the given data written to the old and new buffers.

pub fn new(&mut self) -> &mut T[src]

Get mutable access to the new values in the buffer.

pub fn old(&self) -> &T[src]

Get immutable access to the old values in the buffer.

pub fn swap_buffers(&mut self)[src]

Swap the new and the old buffers (i.e. set the new updated data to be the old data).

Auto Trait Implementations

impl<T> RefUnwindSafe for UpdateBuffer<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for UpdateBuffer<T> where
    T: Send
[src]

impl<T> Sync for UpdateBuffer<T> where
    T: Sync
[src]

impl<T> Unpin for UpdateBuffer<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for UpdateBuffer<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.