diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/transform.rs b/src/transform.rs index ae345c8..c56bec1 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -1,4 +1,7 @@ -use std::{collections::HashMap, rc::Rc}; +use std::{ + collections::{HashMap, HashSet}, + rc::Rc, +}; use proc_macro2::Span; use quote::quote; @@ -20,6 +23,7 @@ pub struct TypeConverter { pub collections: HashMap<Ident, usize>, pub trait_ident: Ident, pub type_conversions: HashMap<Type, Rc<Convert>>, + pub used_conversions: HashSet<Type>, } #[derive(Debug)] @@ -60,8 +64,12 @@ impl TypeConverter { None } - pub fn convert_type(&self, type_: &mut Type) -> Result<TypeTransform, (Span, TransformError)> { + pub fn convert_type( + &mut self, + type_: &mut Type, + ) -> Result<TypeTransform, (Span, TransformError)> { if let Some(conv) = self.type_conversions.get(type_) { + self.used_conversions.insert(conv.original_type.clone()); *type_ = conv.dest_type.clone(); return Ok(TypeTransform::Verbatim(conv.clone())); } @@ -223,7 +231,7 @@ impl TypeConverter { pub fn dynamize_function_bounds( generics: &mut Generics, - type_converter: &TypeConverter, + type_converter: &mut TypeConverter, ) -> Result<HashMap<Ident, Vec<TypeTransform>>, (Span, MethodError)> { let mut type_param_transforms = HashMap::new(); @@ -285,7 +293,7 @@ pub fn dynamize_function_bounds( fn dynamize_trait_bound( bound: &mut TraitBound, - type_converter: &TypeConverter, + type_converter: &mut TypeConverter, type_ident: &Ident, type_param_transforms: &mut HashMap<Ident, Vec<TypeTransform>>, ) -> Result<(), (Span, MethodError)> { |