use crate::component::Resource; use std::cmp::Ordering; use std::fmt; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; /// Represents a `ResourceTable` entry for a `waitable` or `waitable-set`. /// /// This is equivalent to a `Resource`, except without any tracking of borrow /// status (since neither `waitable`s nor `waitable-set`s can be borrowed) or /// other resource-specific bookkeeping. pub struct TableId { rep: u32, _marker: PhantomData T>, } pub trait TableDebug { fn type_name() -> &'static str; } impl fmt::Debug for TableId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}({})", T::type_name(), self.rep) } } impl Hash for TableId { fn hash(&self, state: &mut H) { self.rep.hash(state) } } impl PartialEq for TableId { fn eq(&self, other: &Self) -> bool { self.rep == other.rep } } impl Eq for TableId {} impl PartialOrd for TableId { fn partial_cmp(&self, other: &Self) -> Option { self.rep.partial_cmp(&other.rep) } } impl Ord for TableId { fn cmp(&self, other: &Self) -> Ordering { self.rep.cmp(&other.rep) } } impl TableId { pub fn new(rep: u32) -> Self { Self { rep, _marker: PhantomData, } } } impl Clone for TableId { fn clone(&self) -> Self { Self::new(self.rep) } } impl Copy for TableId {} impl TableId { pub fn rep(&self) -> u32 { self.rep } } impl From> for TableId { fn from(value: Resource) -> Self { Self { rep: value.rep(), _marker: PhantomData, } } } impl From> for Resource { fn from(value: TableId) -> Self { Resource::new_own(value.rep) } }