From 01b6f2c2218b786313c7a887b6fb888343dbafd2 Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Mon, 4 Dec 2023 17:53:21 +0800 Subject: [PATCH] `definition_named_data_type` use `Type::definition` + `reference::custom` --- macros/src/type/mod.rs | 10 +++++++--- src/datatype/reference.rs | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/macros/src/type/mod.rs b/macros/src/type/mod.rs index 20edafe..7c2ce81 100644 --- a/macros/src/type/mod.rs +++ b/macros/src/type/mod.rs @@ -167,9 +167,13 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result #crate_ref::NamedDataType { - Self::named_data_type( - type_map, - &DEFINITION_GENERICS + #crate_ref::internal::construct::named_data_type( + #name.into(), + #comments.into(), + #deprecated, + SID, + IMPL_LOCATION, + ::definition(type_map) ) } } diff --git a/src/datatype/reference.rs b/src/datatype/reference.rs index 12e36fd..b3ab2b0 100644 --- a/src/datatype/reference.rs +++ b/src/datatype/reference.rs @@ -19,7 +19,6 @@ pub fn inline(type_map: &mut TypeMap, generics: &[DataType]) - pub fn reference(type_map: &mut TypeMap, reference: DataTypeReference) -> Reference { if type_map.map.get(&T::SID).is_none() { type_map.map.entry(T::SID).or_insert(None); - let dt = T::definition_named_data_type(type_map); type_map.map.insert(T::SID, Some(dt)); } @@ -28,3 +27,10 @@ pub fn reference(type_map: &mut TypeMap, reference: DataTypeRefere inner: DataType::Reference(reference), } } + +/// Construct a reference from a custom [DataType]. +/// +/// This function is advanced and should only be used if you know what you're doing. +pub fn custom(inner: DataType) -> Reference { + Reference { inner } +}