replace_types/lib.rs
1use std::collections::HashMap;
2
3pub use syn::{visit_mut::VisitMut, TypePath};
4
5/// A [`syn`] [visitor](syn::visit_mut::VisitMut) that replaces types
6pub struct ReplaceTypes(HashMap<TypePath, TypePath>);
7
8impl ReplaceTypes {
9 pub fn new(substitutions: HashMap<TypePath, TypePath>) -> Self {
10 ReplaceTypes(substitutions)
11 }
12}
13
14impl VisitMut for ReplaceTypes {
15 fn visit_type_path_mut(&mut self, node: &mut TypePath) {
16 if let Some(substitution) = self.0.get(node) {
17 *node = substitution.to_owned();
18 }
19 }
20}