go_away/alias.rs
1use super::{TypeMetadata, TypeRegistry};
2
3/// A trait for types that can be registered as aliases.
4///
5/// Users shouldn't usually need to impl this - a blanket impl is provided
6/// for all types that impl `TypeMetadata`.
7pub trait TypeAlias {
8 /// Registers this type as a type alias.
9 ///
10 /// Note that this should not be used on types which have `TypeMetadata`
11 /// derived on them - it's only really meant for use on actual rust type
12 /// aliases.
13 fn register_alias(name: &str, registry: &mut TypeRegistry);
14}
15
16impl<T> TypeAlias for T
17where
18 T: TypeMetadata + 'static,
19{
20 fn register_alias(name: &str, registry: &mut TypeRegistry) {
21 let inner = Self::metadata(registry);
22 registry.register_alias(
23 crate::TypeId::for_type::<Self>(),
24 crate::types::Alias {
25 name: name.to_string(),
26 inner,
27 },
28 );
29 }
30}