| 807 | } |
| 808 | |
| 809 | fn change_namespace_with_docs(&mut self, target: &[String], docs: Option<&str>) { |
| 810 | let mut same = 0; |
| 811 | // itertools::fold_while? |
| 812 | for (a, b) in self.namespace.iter().zip(target.iter()) { |
| 813 | if a == b { |
| 814 | same += 1; |
| 815 | } else { |
| 816 | break; |
| 817 | } |
| 818 | } |
| 819 | for _i in same..self.namespace.len() { |
| 820 | uwrite!(self.src, "}}\n"); |
| 821 | } |
| 822 | self.namespace.truncate(same); |
| 823 | let new_namespaces: Vec<_> = target.iter().skip(same).collect(); |
| 824 | if !new_namespaces.is_empty() { |
| 825 | if let Some(content) = docs { |
| 826 | for line in content.trim().lines() { |
| 827 | uwriteln!(self.src, "/// {}", line); |
| 828 | } |
| 829 | } |
| 830 | for i in &new_namespaces { |
| 831 | uwrite!(self.src, "namespace {} {{\n", i); |
| 832 | self.namespace.push(i.to_string()); |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | fn qualify(&mut self, target: &[String]) { |
| 838 | let mut same = 0; |