Struct sb_rust_library::update_buffer::UpdateBuffer [−][src]
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:
- It makes the update step in an algorithm clean and explicit.
- It allocates all memory used at initialization so the algorithm doesn't have to allocate memory in each step.
- 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]
T: RefUnwindSafe,
impl<T> Send for UpdateBuffer<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for UpdateBuffer<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for UpdateBuffer<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for UpdateBuffer<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,