Skip to main content

ResHandle

Struct ResHandle 

Source
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>

Source

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.

Source

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.

Source

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>

Source

fn shared<K>(&self) -> ResHandle<K>

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§

Source§

impl<R> Clone for ResHandle<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for ResHandle<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R> Eq for ResHandle<R>

Source§

impl<R> Hash for ResHandle<R>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<R> Ord for ResHandle<R>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<R> PartialEq for ResHandle<R>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<R> PartialOrd for ResHandle<R>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<R> Forget for ResHandle<R>

§

impl<R> Freeze for ResHandle<R>
where PhantomData<fn() -> R>: Freeze,

§

impl<R> RefUnwindSafe for ResHandle<R>
where PhantomData<fn() -> R>: RefUnwindSafe,

§

impl<R> Send for ResHandle<R>
where PhantomData<fn() -> R>: Send,

§

impl<R> Sync for ResHandle<R>
where PhantomData<fn() -> R>: Sync,

§

impl<R> Unpin for ResHandle<R>
where PhantomData<fn() -> R>: Unpin,

§

impl<R> UnsafeUnpin for ResHandle<R>
where PhantomData<fn() -> R>: UnsafeUnpin,

§

impl<R> UnwindSafe for ResHandle<R>
where PhantomData<fn() -> R>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsId for T
where T: Hash + Debug,

§

impl<T> AsIdSalt for T
where T: Hash + Debug,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more