pub struct ResHandle<R = Resource> {
node: NodeId,
strong: Arc<()>,
kind: PhantomData<fn() -> R>,
}Expand description
Handle to a resource stored in a ResourceGraph, typed by its kind.
R is the ResourceKind the id names, which is also what the graph hands
back for it: a ResHandle<wgpu::Buffer> resolves to a
buffer, a ResHandle<wgpu::TextureView> to a view. The
default, Resource, is the erased kind — an id to a resource whose kind
is known only at runtime — which is what graph-wide reads like
ResourceGraph::dependencies hand out.
An id names a strong reference to its resource: cloning one takes another
reference, dropping one gives it up, and
ResourceGraph::maintain collects the resource once the last reference is
gone. That is what makes an id safe to hold — the resource it names outlives
every id to it, and a caller that drops its last id lets the graph free the
resource without any further call.
An id therefore resolves for as long as the caller holds it: the graph never
collects a resource some id still names. Letting go of the last id is the
only way to give a resource up, and it takes effect at the next
ResourceGraph::maintain.
An id is not Copy: cloning one adds a reference, which a copy could not
tell apart from a move. Pass one to a graph method by reference.
Fields§
§node: NodeId§strong: Arc<()>The strong reference this id carries. Its liveness is the token’s own reference count.
kind: PhantomData<fn() -> R>Implementations§
Source§impl<R> ResHandle<R>
impl<R> ResHandle<R>
Sourcepub fn index(&self) -> usize
pub fn index(&self) -> usize
The graph index this id refers to.
Only meaningful while the resource lives, but stable across the
resource’s lifetime: callers can group or sort by it (ordering draws
so consecutive ones share a bind group, for example) without holding
a borrow. The index alone does not identify the resource across a
removal and reuse of its slot; ResHandle::id does.
Sourcepub fn id(&self) -> ResId
pub fn id(&self) -> ResId
The resource’s ResId, for an API that stores ids but does not know
the type — an inspector that reports one, or a transport that carries
it.
The id names the resource but holds no reference to it, so it is
Copy. Resolve it back through the graph with
ResourceGraph::resolve, which reports None once the slot has
been recycled.
Sourcepub fn erase(&self) -> ResHandle
pub fn erase(&self) -> ResHandle
Forget the kind, yielding an id to the same resource that claims none.
This is how a typed id is handed to an API that works in any kind — the
erased ResHandle<Resource> that
ResourceGraph::dependencies speaks in, or a stored field a caller
only ever passes back to the graph. The kind is the only thing that
changes: a strong id stays strong through the call, so the erased id
names the same reference and both ids keep the resource alive.
Source§impl<R> ResHandle<R>
impl<R> ResHandle<R>
A second id to the same resource, taking one more strong reference to it.
The new id may name any kind: the node is what both ids resolve
through, and the kind only says which accessor fits. Both Clone and
Self::erase go through here so that a new id always counts,
whichever way it was made.
Trait Implementations§
impl<R> Eq for ResHandle<R>
Source§impl<R> Ord for ResHandle<R>
impl<R> Ord for ResHandle<R>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<R> PartialOrd for ResHandle<R>
impl<R> PartialOrd for ResHandle<R>
Auto Trait Implementations§
impl<R> Forget for ResHandle<R>
impl<R> Freeze for ResHandle<R>
impl<R> RefUnwindSafe for ResHandle<R>
impl<R> Send for ResHandle<R>
impl<R> Sync for ResHandle<R>
impl<R> Unpin for ResHandle<R>
impl<R> UnsafeUnpin for ResHandle<R>
impl<R> UnwindSafe for ResHandle<R>
Blanket Implementations§
impl<T> AsId for T
impl<T> AsIdSalt for T
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§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