Struct ide::CrateGraph
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§
§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: Arc<CfgOptions>, potential_cfg_options: Option<Arc<CfgOptions>>, env: Env, is_proc_macro: bool, origin: CrateOrigin, ) -> Idx<CrateData>
pub fn add_dep( &mut self, from: Idx<CrateData>, dep: Dependency, ) -> Result<(), CyclicDependenciesError>
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn iter(&self) -> impl Iterator<Item = Idx<CrateData>>
pub fn transitive_deps(
&self,
of: Idx<CrateData>,
) -> impl Iterator<Item = Idx<CrateData>>
pub fn transitive_deps( &self, of: Idx<CrateData>, ) -> impl Iterator<Item = Idx<CrateData>>
Returns an iterator over all transitive dependencies of the given crate, including the crate itself.
pub fn transitive_rev_deps(
&self,
of: Idx<CrateData>,
) -> impl Iterator<Item = Idx<CrateData>>
pub fn transitive_rev_deps( &self, of: Idx<CrateData>, ) -> impl Iterator<Item = Idx<CrateData>>
Returns all transitive reverse dependencies of the given crate, including the crate itself.
pub fn crates_in_topological_order(&self) -> Vec<Idx<CrateData>>
pub fn crates_in_topological_order(&self) -> Vec<Idx<CrateData>>
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)
pub fn extend(
&mut self,
other: CrateGraph,
proc_macros: &mut HashMap<Idx<CrateData>, Result<(String, AbsPathBuf), String>, FxBuildHasher>,
) -> HashMap<Idx<CrateData>, Idx<CrateData>, FxBuildHasher>
pub fn extend( &mut self, other: CrateGraph, proc_macros: &mut HashMap<Idx<CrateData>, Result<(String, AbsPathBuf), String>, FxBuildHasher>, ) -> HashMap<Idx<CrateData>, Idx<CrateData>, FxBuildHasher>
Extends this crate graph by adding a complete second crate
graph and adjust the ids in the [ProcMacroPaths
] accordingly.
Returns a map mapping other
’s IDs to the new IDs in self
.
pub fn patch_cfg_if(&mut self) -> bool
pub fn remove_crates_except(
&mut self,
to_keep: &[Idx<CrateData>],
) -> Vec<Option<Idx<CrateData>>>
pub fn remove_crates_except( &mut self, to_keep: &[Idx<CrateData>], ) -> Vec<Option<Idx<CrateData>>>
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§
§impl Clone for CrateGraph
impl Clone for CrateGraph
§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§impl Debug for CrateGraph
impl Debug for CrateGraph
§impl Default for CrateGraph
impl Default for CrateGraph
§fn default() -> CrateGraph
fn default() -> CrateGraph
Auto Trait Implementations§
impl Freeze for CrateGraph
impl RefUnwindSafe for CrateGraph
impl Send for CrateGraph
impl Sync for CrateGraph
impl Unpin for CrateGraph
impl UnwindSafe for CrateGraph
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Cast for T
impl<T> Cast for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more