Struct SlabBuffer
pub struct SlabBuffer<T> { /* private fields */ }
Expand description
A thin wrapper around a buffer T
that provides the ability to tell
if the buffer has been invalidated by the SlabAllocator
that it
originated from.
Invalidation happens when the slab resizes. For this reason it is
important to create as many values as necessary before calling
SlabAllocator::commit
to avoid unnecessary invalidation.
Implementations§
§impl<T> SlabBuffer<T>
impl<T> SlabBuffer<T>
pub fn creation_time(&self) -> usize
pub fn creation_time(&self) -> usize
Returns the timestamp at which the internal buffer was created.
The returned timestamp is not a unix timestamp. It is a monotonically increasing count of buffer invalidations.
pub fn is_invalid(&self) -> bool
pub fn is_invalid(&self) -> bool
Determines whether this buffer has been invalidated by the slab it originated from.
pub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Determines whether this buffer has been invalidated by the slab it originated from.
pub fn is_new_this_commit(&self) -> bool
pub fn is_new_this_commit(&self) -> bool
Returns true
when the slab’s internal buffer has been recreated, and this is that
newly created buffer.
This will return false if SlabAllocator::commit
has been called since the creation
of this buffer.
Typically this function is used by structs that own the SlabAllocator
. These owning
structs will call SlabAllocator::commit
which returns a SlabBuffer
. The callsite
can then call SlabBuffer::is_new_this_commit
to determine if any
downstream resources (like bindgroups) need to be recreated.
This pattern keeps the owning struct from having to also store the SlabBuffer
.
pub fn is_new_this_upkeep(&self) -> bool
is_new_this_commit
insteadpub fn update_if_invalid(&mut self) -> bool
pub fn update_if_invalid(&mut self) -> bool
Syncronize the buffer with the slab’s internal buffer.
This checks to ensure that the internal buffer is the one the slab is working with, and updates it if the slab is working with a newer buffer.
Returns true
if the buffer was updated.
Returns false
if the buffer remains the same.
Use the result of this function to invalidate any bind groups or other downstream resources.
§Note
Be cautious when using this function with multiple buffers to invalidate downstream resources. Keep in mind that using the lazy boolean operators might not have the effect you are expecting!
For example:
use craballoc::prelude::*;
let buffer_a: SlabBuffer<wgpu::Buffer> = todo!();
let buffer_b: SlabBuffer<wgpu::Buffer> = todo!();
let buffer_c: SlabBuffer<wgpu::Buffer> = todo!();
let should_invalidate = buffer_a.update_if_invalid()
|| buffer_b.update_if_invalid()
|| buffer_c.update_if_invalid();
If buffer_a
is invalid, neither buffer_b
nor buffer_c
will be synchronized, because
||
is lazy in its parameter evaluation.
Instead, we should write the following:
use craballoc::prelude::*;
let buffer_a: SlabBuffer<wgpu::Buffer> = todo!();
let buffer_b: SlabBuffer<wgpu::Buffer> = todo!();
let buffer_c: SlabBuffer<wgpu::Buffer> = todo!();
let buffer_a_invalid = buffer_a.update_if_invalid();
let buffer_b_invalid = buffer_b.update_if_invalid();
let buffer_c_invalid = buffer_c.update_if_invalid();
let should_invalidate = buffer_a_invalid || buffer_b_invalid || buffer_c_invalid;
pub fn synchronize(&mut self) -> bool
update_if_invalid
insteadTrait Implementations§
§impl<T> Clone for SlabBuffer<T>
impl<T> Clone for SlabBuffer<T>
§fn clone(&self) -> SlabBuffer<T>
fn clone(&self) -> SlabBuffer<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<T> Deref for SlabBuffer<T>
impl<T> Deref for SlabBuffer<T>
Auto Trait Implementations§
impl<T> Freeze for SlabBuffer<T>
impl<T> RefUnwindSafe for SlabBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for SlabBuffer<T>
impl<T> Sync for SlabBuffer<T>
impl<T> Unpin for SlabBuffer<T>
impl<T> UnwindSafe for SlabBuffer<T>where
T: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);