Skip to content

Commit

Permalink
definition_named_data_type use Type::definition + `reference::cus…
Browse files Browse the repository at this point in the history
…tom`
  • Loading branch information
oscartbeaumont committed Dec 4, 2023
1 parent aa6676c commit 01b6f2c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions macros/src/type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ pub fn derive(input: proc_macro::TokenStream) -> syn::Result<proc_macro::TokenSt
}

fn definition_named_data_type(type_map: &mut #crate_ref::TypeMap) -> #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,
<Self as #crate_ref::Type>::definition(type_map)
)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/datatype/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn inline<T: Type + ?Sized>(type_map: &mut TypeMap, generics: &[DataType]) -
pub fn reference<T: NamedType>(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));
}
Expand All @@ -28,3 +27,10 @@ pub fn reference<T: NamedType>(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 }
}

0 comments on commit 01b6f2c

Please sign in to comment.