Skip to main content

turbo_tasks/registry/
registry_type.rs

1use std::{any::TypeId, cell::SyncUnsafeCell, fmt::Debug};
2
3pub struct RegistryType {
4    // The globally unique name for this function, used when persisting.
5    pub global_name: &'static str,
6    /// A readable name of the function that is used to reporting purposes.
7    pub name: &'static str,
8    /// The type's globally-unique TypeId.
9    pub type_id: TypeId,
10    /// Assigned during registry init (single-threaded inside Lazy).
11    pub(crate) id: SyncUnsafeCell<u16>,
12}
13
14impl Eq for RegistryType {}
15impl PartialEq for RegistryType {
16    fn eq(&self, other: &Self) -> bool {
17        self.type_id == other.type_id
18    }
19}
20
21impl Debug for RegistryType {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        f.write_str(self.global_name)
24    }
25}
26
27impl RegistryType {
28    pub const fn new<T: 'static>(name: &'static str, global_name: &'static str) -> Self {
29        Self {
30            name,
31            global_name,
32            type_id: TypeId::of::<T>(),
33            id: SyncUnsafeCell::new(0),
34        }
35    }
36}