Struct ra_ap_base_db::CrateGraph
source · pub struct CrateGraph { /* private fields */ }
Expand description
CrateGraph
is a bit of information which turns a set of text files into a
number of Rust crates.
Each crate is defined by the FileId
of its root module, the set of enabled
cfg
flags and the set of dependencies.
Note that, due to cfg’s, there might be several crates for a single FileId
!
For the purposes of analysis, a crate does not have a name. Instead, names are specified on dependency edges. That is, a crate might be known under different names in different dependent crates.
Note that CrateGraph
is build-system agnostic: it’s a concept of the Rust
language proper, not a concept of the build system. In practice, we get
CrateGraph
by lowering cargo metadata
output.
CrateGraph
is !Serialize
by design, see
https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/architecture.md#serialization
Implementations§
source§impl CrateGraph
impl CrateGraph
pub fn add_crate_root( &mut self, root_file_id: FileId, edition: Edition, display_name: Option<CrateDisplayName>, version: Option<String>, cfg_options: CfgOptions, potential_cfg_options: Option<CfgOptions>, env: Env, is_proc_macro: bool, origin: CrateOrigin ) -> CrateId
sourcepub fn remove_and_replace(
&mut self,
id: CrateId,
replace_with: CrateId
) -> Result<(), CyclicDependenciesError>
pub fn remove_and_replace( &mut self, id: CrateId, replace_with: CrateId ) -> Result<(), CyclicDependenciesError>
Remove the crate from crate graph. If any crates depend on this crate, the dependency would be replaced with the second input.
pub fn add_dep( &mut self, from: CrateId, dep: Dependency ) -> Result<(), CyclicDependenciesError>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn iter(&self) -> impl Iterator<Item = CrateId> + '_
sourcepub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId>
pub fn transitive_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId>
Returns an iterator over all transitive dependencies of the given crate, including the crate itself.
sourcepub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId>
pub fn transitive_rev_deps(&self, of: CrateId) -> impl Iterator<Item = CrateId>
Returns all transitive reverse dependencies of the given crate, including the crate itself.
sourcepub fn crates_in_topological_order(&self) -> Vec<CrateId>
pub fn crates_in_topological_order(&self) -> Vec<CrateId>
Returns all crates in the graph, sorted in topological order (ie. dependencies of a crate come before the crate itself).
pub fn sort_deps(&mut self)
sourcepub fn extend(
&mut self,
other: CrateGraph,
proc_macros: &mut ProcMacroPaths,
merge: impl Fn((CrateId, &mut CrateData), (CrateId, &CrateData)) -> bool
) -> FxHashMap<CrateId, CrateId>
pub fn extend( &mut self, other: CrateGraph, proc_macros: &mut ProcMacroPaths, merge: impl Fn((CrateId, &mut CrateData), (CrateId, &CrateData)) -> bool ) -> FxHashMap<CrateId, CrateId>
Extends this crate graph by adding a complete disjoint second crate
graph and adjust the ids in the ProcMacroPaths
accordingly.
This will deduplicate the crates of the graph where possible.
Note that for deduplication to fully work, self
’s crate dependencies must be sorted by crate id.
If the crate dependencies were sorted, the resulting graph from this extend
call will also
have the crate dependencies sorted.
Returns a mapping from other
’s crate ids to the new crate ids in self
.
pub fn patch_cfg_if(&mut self) -> bool
sourcepub fn remove_crates_except(
&mut self,
to_keep: &[CrateId]
) -> Vec<Option<CrateId>>
pub fn remove_crates_except( &mut self, to_keep: &[CrateId] ) -> Vec<Option<CrateId>>
Removes all crates from this crate graph except for the ones in to_keep
and fixes up the dependencies.
Returns a mapping from old crate ids to new crate ids.
pub fn shrink_to_fit(&mut self)
Trait Implementations§
source§impl Clone for CrateGraph
impl Clone for CrateGraph
source§fn clone(&self) -> CrateGraph
fn clone(&self) -> CrateGraph
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more