| 468 | } |
| 469 | |
| 470 | pub fn new<I>(iter: I, root: Option<PathBuf>) -> Self |
| 471 | where |
| 472 | I: IntoIterator<Item = (PathBuf, String)>, |
| 473 | { |
| 474 | let mut res = SourceTree { |
| 475 | sources: HashMap::new(), |
| 476 | source_ids: HashMap::new(), |
| 477 | root, |
| 478 | }; |
| 479 | |
| 480 | for (index, (path, content)) in iter.into_iter().enumerate() { |
| 481 | res.sources.insert(path.clone(), content); |
| 482 | res.source_ids.insert((index + 1) as u16, path); |
| 483 | } |
| 484 | res |
| 485 | } |
| 486 | |
| 487 | pub fn insert(&mut self, path: PathBuf, content: String) { |
| 488 | let last_id = self.source_ids.keys().max().cloned().unwrap_or(0); |