mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
feat(literal): a helper to convert Ident to Literal
This commit is contained in:
parent
d835b0782c
commit
4966acbc64
5 changed files with 13 additions and 14 deletions
|
@ -112,7 +112,7 @@ fn ingredients_for_impl(
|
|||
data_ty: &syn::Type,
|
||||
) -> syn::ItemImpl {
|
||||
let jar_ty = args.jar_ty();
|
||||
let debug_name = proc_macro2::Literal::string(&struct_name.to_string());
|
||||
let debug_name = crate::literal(struct_name);
|
||||
parse_quote! {
|
||||
impl salsa::storage::IngredientsFor for #struct_name {
|
||||
type Ingredients = salsa::accumulator::AccumulatorIngredient<#data_ty>;
|
||||
|
|
|
@ -130,17 +130,14 @@ impl InputStruct {
|
|||
/// The entity's ingredients include both the main entity ingredient along with a
|
||||
/// function ingredient for each of the value fields.
|
||||
fn input_ingredients(&self) -> syn::ItemImpl {
|
||||
use crate::literal;
|
||||
let ident = self.id_ident();
|
||||
let field_ty = self.all_field_tys();
|
||||
let jar_ty = self.jar_ty();
|
||||
let all_field_indices: Vec<Literal> = self.all_field_indices();
|
||||
let input_index: Literal = self.input_index();
|
||||
let debug_name_struct = Literal::string(&self.id_ident().to_string());
|
||||
let debug_name_fields: Vec<_> = self
|
||||
.all_field_names()
|
||||
.into_iter()
|
||||
.map(|ident| Literal::string(&ident.to_string()))
|
||||
.collect();
|
||||
let debug_name_struct = literal(self.id_ident());
|
||||
let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect();
|
||||
|
||||
parse_quote! {
|
||||
impl salsa::storage::IngredientsFor for #ident {
|
||||
|
|
|
@ -25,6 +25,11 @@ macro_rules! parse_quote_spanned {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert a single Ident to Literal: useful when &'static str is needed.
|
||||
pub(crate) fn literal(ident: &proc_macro2::Ident) -> proc_macro2::Literal {
|
||||
proc_macro2::Literal::string(&ident.to_string())
|
||||
}
|
||||
|
||||
mod accumulator;
|
||||
mod configuration;
|
||||
mod db;
|
||||
|
|
|
@ -243,7 +243,7 @@ fn ingredients_for_impl(
|
|||
let lru = args.lru.unwrap_or(0);
|
||||
|
||||
// get the name of the function as a string literal
|
||||
let debug_name = Literal::string(&item_fn.sig.ident.to_string());
|
||||
let debug_name = crate::literal(&item_fn.sig.ident);
|
||||
|
||||
parse_quote! {
|
||||
impl salsa::storage::IngredientsFor for #config_ty {
|
||||
|
|
|
@ -153,18 +153,15 @@ impl TrackedStruct {
|
|||
/// The tracked struct's ingredients include both the main tracked struct ingredient along with a
|
||||
/// function ingredient for each of the value fields.
|
||||
fn tracked_struct_ingredients(&self, config_structs: &[syn::ItemStruct]) -> syn::ItemImpl {
|
||||
use crate::literal;
|
||||
let ident = self.id_ident();
|
||||
let jar_ty = self.jar_ty();
|
||||
let id_field_tys: Vec<&syn::Type> = self.id_fields().map(SalsaField::ty).collect();
|
||||
let value_field_indices: Vec<Literal> = self.value_field_indices();
|
||||
let tracked_struct_index: Literal = self.tracked_struct_index();
|
||||
let config_struct_names = config_structs.iter().map(|s| &s.ident);
|
||||
let debug_name_struct = Literal::string(&self.id_ident().to_string());
|
||||
let debug_name_fields: Vec<_> = self
|
||||
.all_field_names()
|
||||
.into_iter()
|
||||
.map(|ident| Literal::string(&ident.to_string()))
|
||||
.collect();
|
||||
let debug_name_struct = literal(self.id_ident());
|
||||
let debug_name_fields: Vec<_> = self.all_field_names().into_iter().map(literal).collect();
|
||||
|
||||
parse_quote! {
|
||||
impl salsa::storage::IngredientsFor for #ident {
|
||||
|
|
Loading…
Reference in a new issue