pub struct Handle<T> {
index: NonMaxU32,
marker: PhantomData<T>,
}
Expand description
A strongly typed reference to an arena item.
A Handle
value can be used as an index into an Arena
or UniqueArena
.
Fields§
§index: NonMaxU32
§marker: PhantomData<T>
Implementations§
source§impl<T> Handle<T>
impl<T> Handle<T>
pub(crate) const fn new(index: NonMaxU32) -> Self
sourcepub(super) fn from_usize(index: usize) -> Self
pub(super) fn from_usize(index: usize) -> Self
Convert a usize
index into a Handle<T>
.
sourcepub(super) const unsafe fn from_usize_unchecked(index: usize) -> Self
pub(super) const unsafe fn from_usize_unchecked(index: usize) -> Self
Convert a usize
index into a Handle<T>
, without range checks.
sourcepub fn write_prefixed(
&self,
formatter: &mut Formatter<'_>,
prefix: &'static str,
) -> Result
pub fn write_prefixed( &self, formatter: &mut Formatter<'_>, prefix: &'static str, ) -> Result
Write this handle’s index to formatter
, preceded by prefix
.
source§impl<T> Handle<T>
impl<T> Handle<T>
sourcefn check_valid_for(self, arena: &Arena<T>) -> Result<(), InvalidHandleError>
fn check_valid_for(self, arena: &Arena<T>) -> Result<(), InvalidHandleError>
Check that self
is valid within arena
using Arena::check_contains_handle
.
sourcefn check_valid_for_uniq(
self,
arena: &UniqueArena<T>,
) -> Result<(), InvalidHandleError>
fn check_valid_for_uniq( self, arena: &UniqueArena<T>, ) -> Result<(), InvalidHandleError>
Check that self
is valid within arena
using UniqueArena::check_contains_handle
.
sourcefn check_dep(self, depends_on: Self) -> Result<Self, FwdDepError>
fn check_dep(self, depends_on: Self) -> Result<Self, FwdDepError>
Check that depends_on
was constructed before self
by comparing handle indices.
If self
is a valid handle (i.e., it has been validated using Self::check_valid_for
)
and this function returns Ok
, then it may be assumed that depends_on
is also valid.
In naga
’s current arena-based implementation, this is useful for validating
recursive definitions of arena-based values in linear time.
§Errors
If depends_on
’s handle is from the same Arena
as self'
s, but not constructed earlier
than self
’s, this function returns an error.
sourcefn check_dep_opt(self, depends_on: Option<Self>) -> Result<Self, FwdDepError>
fn check_dep_opt(self, depends_on: Option<Self>) -> Result<Self, FwdDepError>
Like Self::check_dep
, except for Option
al handle values.
sourcefn check_dep_iter(
self,
depends_on: impl Iterator<Item = Self>,
) -> Result<Self, FwdDepError>
fn check_dep_iter( self, depends_on: impl Iterator<Item = Self>, ) -> Result<Self, FwdDepError>
Like Self::check_dep
, except for Iterator
s over handle values.
Trait Implementations§
source§impl Index<Handle<Expression>> for CachedExpressions
impl Index<Handle<Expression>> for CachedExpressions
source§impl Index<Handle<Expression>> for ExpressionTypeResolver<'_>
impl Index<Handle<Expression>> for ExpressionTypeResolver<'_>
source§impl Index<Handle<Expression>> for FunctionInfo
impl Index<Handle<Expression>> for FunctionInfo
source§type Output = ExpressionInfo
type Output = ExpressionInfo
source§fn index(&self, handle: Handle<Expression>) -> &ExpressionInfo
fn index(&self, handle: Handle<Expression>) -> &ExpressionInfo
container[index]
) operation. Read moresource§impl Index<Handle<Expression>> for ModuleInfo
impl Index<Handle<Expression>> for ModuleInfo
source§impl Index<Handle<GlobalVariable>> for FunctionInfo
impl Index<Handle<GlobalVariable>> for FunctionInfo
source§impl<T> Index<Handle<T>> for UniqueArena<T>
impl<T> Index<Handle<T>> for UniqueArena<T>
source§impl IndexMut<Handle<Expression>> for CachedExpressions
impl IndexMut<Handle<Expression>> for CachedExpressions
source§impl<T> Ord for Handle<T>
impl<T> Ord for Handle<T>
source§impl<T> PartialOrd for Handle<T>
impl<T> PartialOrd for Handle<T>
impl<T> Copy for Handle<T>
impl<T> Eq for Handle<T>
Auto Trait Implementations§
impl<T> Freeze for Handle<T>
impl<T> RefUnwindSafe for Handle<T>where
T: RefUnwindSafe,
impl<T> Send for Handle<T>where
T: Send,
impl<T> Sync for Handle<T>where
T: Sync,
impl<T> Unpin for Handle<T>where
T: Unpin,
impl<T> UnwindSafe for Handle<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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.