Don't expose indexing details

This commit is contained in:
Aleksey Kladov 2020-08-25 18:39:18 +02:00
parent 13fd8846b4
commit 9786a8f2d4
2 changed files with 20 additions and 24 deletions

View file

@ -12,7 +12,7 @@ use crate::cfg_flag::CfgFlag;
/// Roots and crates that compose this Rust project.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProjectJson {
pub(crate) crates: Vec<Crate>,
crates: Vec<Crate>,
}
/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
@ -79,6 +79,12 @@ impl ProjectJson {
.collect::<Vec<_>>(),
}
}
pub fn n_crates(&self) -> usize {
self.crates.len()
}
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
}
}
#[derive(Deserialize)]