pub struct Rebuild(Arc<dyn Fn(&ResourceGraph) -> Resource>);Expand description
A recipe that builds a resource out of the graph it lives in.
A node that can be rebuilt is inserted with one —
ResourceGraph::insert — and ResourceGraph::maintain
calls it whenever the node is dirty. The recipe reads whatever it was built
from back out of the graph by ResHandle, so it always sees the current
handle of its inputs rather than a copy captured when it was written.
The closure runs while the graph is borrowed immutably, so it can only read the graph: a recipe returns the handle it built and the graph writes it into the node.
Tuple Fields§
§0: Arc<dyn Fn(&ResourceGraph) -> Resource>Implementations§
Source§impl Rebuild
impl Rebuild
Sourcepub fn new(rebuild: impl Fn(&ResourceGraph) -> Resource + 'static) -> Self
pub fn new(rebuild: impl Fn(&ResourceGraph) -> Resource + 'static) -> Self
Wrap rebuild as a reusable recipe.
Only a resource that can be built purely from what the graph holds can be rebuilt lazily; the closure captures the device and the layout it needs on its own.
Sourcepub fn build<R: ResourceKind>(&self, graph: &ResourceGraph) -> R
pub fn build<R: ResourceKind>(&self, graph: &ResourceGraph) -> R
Build the resource from the graph’s current state.
ResourceGraph::maintain calls this for a dirty node, but a caller
can also use it to build the first instance eagerly, when it has to hold
the resource before the next maintain.
§Panics
If the recipe builds a resource of a different kind than R names. A
recipe only ever builds the kind its node stores, so this is a
programming error.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Rebuild
impl !Send for Rebuild
impl !Sync for Rebuild
impl !UnwindSafe for Rebuild
impl Forget for Rebuild
impl Freeze for Rebuild
impl Unpin for Rebuild
impl UnsafeUnpin for Rebuild
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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