Struct double_buffer::DoubleBuffer
source · pub struct DoubleBuffer<T> { /* private fields */ }
Expand description
Encapsulates a piece of state that can be modified and we want all outside code to see the edit as a single atomic change.
There are two ways to swap:
DoubleBuffer::swap()
- when swapping, the next value will have the previous current value.DoubleBuffer::swap_cloning()
- when swapping, the next value will keep same and will be cloned to the current value.
You can read about the two ways how the buffers are swapped in “Game Programming Patterns” by Robert Nystrom.
Examples
use double_buffer::DoubleBuffer;
let mut buffer: DoubleBuffer<u32> = DoubleBuffer::default();
*buffer = 1;
assert_eq!(buffer, 0);
buffer.swap();
assert_eq!(buffer, 1);
Implementations§
source§impl<T> DoubleBuffer<T>
impl<T> DoubleBuffer<T>
source§impl<T: Clone> DoubleBuffer<T>
impl<T: Clone> DoubleBuffer<T>
sourcepub fn swap_cloning(&mut self)
pub fn swap_cloning(&mut self)
Swaps buffers cloning the next value to the current value, then writes will continue over the same next value.
Trait Implementations§
source§impl<T> AsMut<T> for DoubleBuffer<T>
impl<T> AsMut<T> for DoubleBuffer<T>
source§impl<T> AsRef<T> for DoubleBuffer<T>
impl<T> AsRef<T> for DoubleBuffer<T>
source§impl<T> Borrow<T> for DoubleBuffer<T>
impl<T> Borrow<T> for DoubleBuffer<T>
source§impl<T> BorrowMut<T> for DoubleBuffer<T>
impl<T> BorrowMut<T> for DoubleBuffer<T>
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T: Debug> Debug for DoubleBuffer<T>
impl<T: Debug> Debug for DoubleBuffer<T>
source§impl<T: Default> Default for DoubleBuffer<T>
impl<T: Default> Default for DoubleBuffer<T>
source§impl<T> Deref for DoubleBuffer<T>
impl<T> Deref for DoubleBuffer<T>
source§impl<T> DerefMut for DoubleBuffer<T>
impl<T> DerefMut for DoubleBuffer<T>
source§impl<T: PartialEq> PartialEq<T> for DoubleBuffer<T>
impl<T: PartialEq> PartialEq<T> for DoubleBuffer<T>
source§impl<T: PartialOrd> PartialOrd<T> for DoubleBuffer<T>
impl<T: PartialOrd> PartialOrd<T> for DoubleBuffer<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreAuto Trait Implementations§
impl<T> RefUnwindSafe for DoubleBuffer<T>where T: RefUnwindSafe,
impl<T> Send for DoubleBuffer<T>where T: Send,
impl<T> Sync for DoubleBuffer<T>where T: Sync,
impl<T> Unpin for DoubleBuffer<T>where T: Unpin,
impl<T> UnwindSafe for DoubleBuffer<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more