mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-18 10:37:40 +00:00
move interned-specific fns out of salsa struct
Salsa struct is already a grab-bag, best to keep it to shared functionality.
This commit is contained in:
parent
8ba6e606c0
commit
54c9586b45
2 changed files with 38 additions and 34 deletions
components/salsa-2022-macros/src
|
@ -79,6 +79,40 @@ impl InternedStruct {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// The name of the "data" struct (this comes from the `data = Foo` option or,
|
||||
/// if that is not provided, by concatenating `Data` to the name of the struct).
|
||||
fn data_ident(&self) -> syn::Ident {
|
||||
match &self.args().data {
|
||||
Some(d) => d.clone(),
|
||||
None => syn::Ident::new(
|
||||
&format!("__{}Data", self.the_ident()),
|
||||
self.the_ident().span(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates the `struct FooData` struct (or enum).
|
||||
/// This type inherits all the attributes written by the user.
|
||||
///
|
||||
/// When using named fields, we synthesize the struct and field names.
|
||||
///
|
||||
/// When no named fields are available, copy the existing type.
|
||||
fn data_struct(&self) -> syn::ItemStruct {
|
||||
let ident = self.data_ident();
|
||||
let visibility = self.visibility();
|
||||
let all_field_names = self.all_field_names();
|
||||
let all_field_tys = self.all_field_tys();
|
||||
parse_quote_spanned! { ident.span() =>
|
||||
/// Internal struct used for interned item
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
#visibility struct #ident {
|
||||
#(
|
||||
#all_field_names: #all_field_tys,
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If this is an interned struct, then generate methods to access each field,
|
||||
/// as well as a `new` method.
|
||||
fn inherent_impl_for_named_fields(&self) -> syn::ItemImpl {
|
||||
|
|
|
@ -84,6 +84,10 @@ impl<A: AllowedOptions> SalsaStruct<A> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn args(&self) -> &Options<A> {
|
||||
&self.args
|
||||
}
|
||||
|
||||
pub(crate) fn require_no_generics(&self) -> syn::Result<()> {
|
||||
if let Some(param) = self.struct_item.generics.params.iter().next() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
|
@ -268,18 +272,6 @@ impl<A: AllowedOptions> SalsaStruct<A> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The name of the "data" struct (this comes from the `data = Foo` option or,
|
||||
/// if that is not provided, by concatenating `Data` to the name of the struct).
|
||||
pub(crate) fn data_ident(&self) -> syn::Ident {
|
||||
match &self.args.data {
|
||||
Some(d) => d.clone(),
|
||||
None => syn::Ident::new(
|
||||
&format!("__{}Data", self.the_ident()),
|
||||
self.the_ident().span(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create "the struct" whose field is an id.
|
||||
/// This is the struct the user will refernece, but only if there
|
||||
/// are no lifetimes.
|
||||
|
@ -346,28 +338,6 @@ impl<A: AllowedOptions> SalsaStruct<A> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Generates the `struct FooData` struct (or enum).
|
||||
/// This type inherits all the attributes written by the user.
|
||||
///
|
||||
/// When using named fields, we synthesize the struct and field names.
|
||||
///
|
||||
/// When no named fields are available, copy the existing type.
|
||||
pub(crate) fn data_struct(&self) -> syn::ItemStruct {
|
||||
let ident = self.data_ident();
|
||||
let visibility = self.visibility();
|
||||
let all_field_names = self.all_field_names();
|
||||
let all_field_tys = self.all_field_tys();
|
||||
parse_quote_spanned! { ident.span() =>
|
||||
/// Internal struct used for interned item
|
||||
#[derive(Eq, PartialEq, Hash, Clone)]
|
||||
#visibility struct #ident {
|
||||
#(
|
||||
#all_field_names: #all_field_tys,
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the visibility of this item
|
||||
pub(crate) fn visibility(&self) -> &syn::Visibility {
|
||||
&self.struct_item.vis
|
||||
|
|
Loading…
Reference in a new issue