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<'de, T> Deserialize<'de> for Handle<T>
impl<'de, T> Deserialize<'de> for Handle<T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Index<Handle<Expression>> for CachedExpressions
impl Index<Handle<Expression>> for CachedExpressions
source§impl<'a> Index<Handle<Expression>> for ExpressionTypeResolver<'a>
impl<'a> Index<Handle<Expression>> for ExpressionTypeResolver<'a>
source§impl Index<Handle<Expression>> for FunctionInfo
impl Index<Handle<Expression>> for FunctionInfo
§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
§type Output = TypeResolution
type Output = TypeResolution
source§impl Index<Handle<Expression>> for Typifier
impl Index<Handle<Expression>> for Typifier
§type Output = TypeResolution
type Output = TypeResolution
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 Index<Handle<Type>> for Layouter
impl Index<Handle<Type>> for Layouter
§type Output = TypeLayout
type Output = TypeLayout
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> PartialEq for Handle<T>
impl<T> PartialEq for Handle<T>
source§impl<T> PartialOrd for Handle<T>
impl<T> PartialOrd for Handle<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<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<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.