Skip to main content

IndexReader

Struct IndexReader 

Source
pub struct IndexReader<B> { /* private fields */ }
Expand description

Zero-copy reader over a memory-mapped or buffered .ridx index.

Implementations§

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn target_triple(&self) -> &str

Effective target triple recorded for this shard (or "" if none).

Source

pub fn cfgs(&self) -> &[CfgEntry]

Raw slice of CfgEntry rows sorted by (key_str, Option<value_str>).

Source

pub fn cfg_iter( &self, ) -> impl ExactSizeIterator<Item = (&str, Option<&str>)> + '_

Iterates over all (key, Option<value>) cfg predicates in sorted order.

Source

pub fn has_cfg_flag(&self, key: &str) -> bool

O(log N) lookup for a bare cfg flag atom (#[cfg(unix)], #[cfg(test)]).

Source

pub fn has_cfg_key_value(&self, key: &str, value: &str) -> bool

O(log N) lookup for a cfg(key = "value") predicate (#[cfg(feature = "std")]).

Source

pub fn cfg_values<'a>( &'a self, key: &str, ) -> impl ExactSizeIterator<Item = &'a str> + 'a

O(log N) zero-allocation iterator over all values v of cfg(key = "v") in sorted order.

Source

pub fn enabled_features(&self) -> impl ExactSizeIterator<Item = &str> + '_

O(log N) zero-allocation iterator over all enabled Cargo features (feature = "...").

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn find_definition_at( &self, file: &str, line: u32, col: u32, ) -> Option<ResolvedDefinition<'_>>

Go to definition at a given cursor position (file, line, col).

The innermost name reference at the cursor answers, unless a definition at the cursor lies inside that reference’s span: a reference spanning a macro invocation or a generated call encloses every item written inside it, and on such an item’s name the item is the answer. Equal spans (a self-reference) keep the reference. A reference as wide as its target’s name cannot enclose a definition, so no definition is looked for behind it. Without a reference the smallest named definition containing the cursor answers; the nameless crate-root module the driver records with the span of the whole file never does, so a position on no name has no definition.

Source

pub fn find_innermost_ref_at( &self, file: &str, line: u32, col: u32, ) -> Option<&RefEntry>

Finds the innermost RefEntry at (file, line, col) via binary search on span-sorted references.

Source

pub fn find_innermost_ref_at_file_id( &self, file_id: u32, line: u32, col: u32, ) -> Option<&RefEntry>

Finds the innermost RefEntry at (file_id, line, col) via binary search on span-sorted references. References that are not uses of a name (is_name_reference) are skipped.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn find_file_id(&self, file_path: &str) -> Option<u32>

Looks up the file_id of the file stored as file_path: the same string, or the same path by components (./src/lib.rs and src//lib.rs name src/lib.rs), or a stored path whose .. components resolve lexically to it: a file pulled in by include!("../test_data/x.rs") is stored as rustc spelled it, crate/src/../test_data/x.rs, and crate/test_data/x.rs names it. .. on the query side is not resolved here: through a symlinked parent it is a filesystem question, which WorkspaceIndex settles before asking. A path that merely ends with a stored one, such as another crate’s src/lib.rs, does not match. The stored form is the one the driver wrote: relative to the workspace root for workspace crates, relative to the package directory for dependencies, relative to the rust-src root for the sysroot; WorkspaceIndex::target_file_for_reader turns any input into it.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn macro_defs(&self) -> &[MacroDefEntry]

Raw slice of MacroDefEntry rows sorted by def_index.

Source

pub fn macro_defs_iter( &self, ) -> impl ExactSizeIterator<Item = MacroDefView<'_>> + '_

Iterates over all decoded MacroDefView entries in def_index order.

Source

pub fn macro_def_for_def(&self, def_index: u32) -> Option<MacroDefView<'_>>

O(log N) lookup for the declarative macro definition owned by def_index.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn has_macro_expansion_reference( &self, target_path: &str, def_line: u32, ) -> bool

Whether a macro expansion wrote a reference to target_path whose target sits on 1-based def_line (0 matches any). Unlike find_references this counts the references that are no use of the name, such as a proc macro’s generated call carrying its call site’s span: rename safety needs to know the call exists.

Source

pub fn is_name_reference(&self, r: &RefEntry) -> bool

True when r is a use of its target’s name. A reference whose span properly encloses the span of its own target’s definition is not one: it is the span of the item or file that defines the target. The driver writes two such references per #[test] function: a plain Fn reference spanning the whole function (the call the test harness generates) and a macro Const reference to the generated test constant spanning the whole file or module (the constant’s definition sits on the #[test] attribute, so the span begins where the definition begins and reaches far past it); derive expansions add references spanning a whole variant or field. A definition whose end lies before its start (an index without end spans) is never enclosed. The reader’s lookups (find_innermost_ref_at_file_id, find_references) skip references that fail this test; IndexReader::references still returns every record.

Source

pub fn may_enclose_definition(&self, r: &RefEntry) -> bool

True when the span of r can contain a definition’s name span: a span over more than one line, or a single-line span wider than its target’s name. A reference as wide as the name it uses contains no definition, so find_definition_at answers it without looking for one; a span whose end lies before its start contains nothing.

Source

pub fn qualified_item_targets(&self) -> HashMap<Box<str>, Vec<u32>>

The distinct reference target paths that name an implementation’s item (<T as Trait>::item, m::<impl Trait for T>::item), as string offsets grouped by the item’s name. One pass over the target table.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn find_definition_by_path(&self, path: &str) -> Option<&DefEntry>

Find a definition by its canonical path (e.g. stdx::panic_context::enter).

Source

pub fn has_multiple_definitions_at_path(&self, path: &str) -> bool

Returns true when more than one definition in this shard shares path at distinct lines.

Source

pub fn find_definition_by_path_and_id( &self, path: &str, target_def_id: u32, ) -> Option<&DefEntry>

Find a definition by its canonical path and exact def_id.

Source

pub fn resolve_ref_definition(&self, r: &RefEntry) -> ResolvedDefinition<'_>

Resolves a RefEntry to its target ResolvedDefinition.

Source

pub fn find_ref_targeting_position( &self, file_id: u32, line: u32, col: u32, ) -> Option<ResolvedDefinition<'_>>

Resolves a field or variant definition at its declaration line when the index only recorded references to it (e.g. in pre-existing indices where Field/Variant were not in definitions()).

Source

pub fn references_in_file(&self, file_id: u32) -> &[RefEntry]

Returns the contiguous slice of span-sorted references inside file_id.

Source

pub fn references_at_start( &self, file_id: u32, start_line: u32, start_col: u32, ) -> &[RefEntry]

Returns the contiguous slice of span-sorted references starting at (file_id, start_line, start_col).

Source

pub fn find_references(&self, target_path: &str) -> Vec<&RefEntry>

Find all references to a given symbol path (e.g. thread::Builder::allow_leak). References that are not uses of a name (is_name_reference) are left out.

Source

pub fn find_innermost_type_entry( &self, file: &str, line: u32, col: u32, ) -> Option<&TypeEntry>

Finds the innermost TypeEntry at a cursor position (file, line, col).

Source

pub fn find_innermost_type_entry_at_file_id( &self, file_id: u32, line: u32, col: u32, ) -> Option<&TypeEntry>

Finds the innermost TypeEntry at (file_id, line, col) without re-scanning the file table.

Source

pub fn type_at(&self, file: &str, line: u32, col: u32) -> Option<&str>

Retrieves the inferred expression type at a cursor position (file, line, col). When nested expressions overlap, selects the tightest (innermost) span.

Source

pub fn type_entry_at( &self, file: &str, line: u32, col: u32, ) -> Option<(&str, Option<&str>)>

Retrieves the inferred expression type and optional canonical owner path at (file, line, col). Returns (type_name, canonical_owner_path).

Source

pub fn type_entry_at_file_id( &self, file_id: u32, line: u32, col: u32, ) -> Option<(&str, Option<&str>)>

Retrieves the inferred expression type and optional canonical owner path at (file_id, line, col).

Source

pub fn find_definitions_by_owner(&self, owner: &str) -> Vec<&DefEntry>

Find all definitions belonging to an owner (canonical type path or module path).

Performs binary search on the 64-bit FNV-1a hash of owner, with full collision verification against the interned canonical owner string.

Source

pub fn find_owners_by_def_index(&self, def_index: u32) -> Vec<&str>

Find all canonical owners associated with a definition index.

Source

pub fn type_param_scope(&self, def_index: u32) -> Option<(u32, u32, u32, u32)>

Returns the lexical enclosing scope coordinates (start_line, start_col, end_line, end_col) for a definition index if recorded.

Source

pub fn find_type_param_in_scope( &self, file: &str, name: &str, line: u32, col: u32, ) -> Option<(&DefEntry, u32)>

Finds a generic type parameter (DefKind::TyParam) in the specified file matching name whose enclosing item span contains (line, col).

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn notes(&self) -> &[NoteEntry]

Slice of all notes in the index (sorted by span); empty for indexes older than format version 4.

Source

pub fn note_at( &self, file_id: u32, line: u32, col: u32, kind: u32, ) -> Option<&str>

The text of the kind note whose span starts at (file_id, line, col).

Source

pub fn ty_defs(&self) -> &[TyDefEntry]

Raw slice of TyDefEntry records in this shard’s TyArena (empty for format < v5).

Source

pub fn ty_entries(&self) -> &[TyEntry]

Raw slice of TyEntry records in this shard’s TyArena (empty for format < v5).

Source

pub fn ty_bounds(&self) -> &[TyBoundEntry]

Raw slice of TyBoundEntry records in this shard’s TyArena (empty for format < v5).

Source

pub fn ty_args_raw(&self) -> &[u32]

Raw slice of u32 words in this shard’s TyArena argument pool (empty for format < v5).

Source

pub fn ty_arena(&self) -> TyArenaView<'_>

Zero-copy TyArenaView over this shard’s interned types and string pool.

Source

pub fn fn_sigs(&self) -> &[FnSigEntry]

Raw slice of sorted FnSigEntry records in this shard (empty for format < v5).

Source

pub fn fn_sig_for_def(&self, def_index: u32) -> Option<FnSigView<'_>>

Looks up the structured FnSigView for def_index in O(log N) via binary search.

Source

pub fn impls(&self) -> &[ImplEntry]

Raw slice of sorted ImplEntry records in this shard (empty for format < v5).

Source

pub fn assoc_tys(&self) -> &[AssocTyEntry]

Raw slice of contiguous AssocTyEntry bindings in this shard (empty for format < v5).

Source

pub fn impl_view(&self, impl_index: u32) -> Option<ImplView<'_>>

Decodes the ImplView at impl_index (0..impls().len()).

Source

pub fn impls_iter(&self) -> ImplIter<'_> ⓘ

Iterates over all ImplView headers in this shard.

Source

pub fn impls_for_simplified(&self, kind: SimplifiedSelfKind) -> ImplIter<'_> ⓘ

Binary-searches all ImplEntry records (both inherent and trait) whose self_ty matches kind.

Source

pub fn inherent_impls_for_simplified( &self, kind: SimplifiedSelfKind, ) -> ImplIter<'_> ⓘ

Binary-searches inherent impl Self blocks whose self_ty matches kind.

Source

pub fn trait_impls_for_simplified( &self, kind: SimplifiedSelfKind, ) -> ImplIter<'_> ⓘ

Binary-searches impl Trait for Self blocks whose self_ty matches kind.

Source

pub fn fields(&self) -> &[FieldEntry]

Raw slice of sorted FieldEntry records in this shard (empty for format < v5).

Source

pub fn fields_for_owner(&self, owner_def_index: u32) -> FieldIter<'_> ⓘ

Binary-searches all FieldEntry rows belonging to owner_def_index (Struct, Union, or Variant).

Source

pub fn find_field( &self, owner_def_index: u32, name: &str, ) -> Option<FieldView<'_>>

Looks up a specific field name (or positional "0", "1") on owner_def_index.

Source

pub fn def_tys(&self) -> &[DefTyEntry]

Raw slice of sorted DefTyEntry records in this shard (empty for format < v5).

Source

pub fn def_ty_for_def(&self, def_index: u32) -> Option<DefTyView>

Looks up the DefTyView (TyAlias RHS, Const/Static/AssocConst type, or ADT/variant ctor shape) for def_index in O(log N) via binary search.

Source

pub fn generic_params(&self) -> &[GenericParamEntry]

Raw slice of sorted GenericParamEntry records in this shard (empty for format < v5).

Source

pub fn generic_params_for_owner( &self, owner: GenericOwner, ) -> GenericParamIter<'_> ⓘ

Binary-searches all GenericParamEntry declarations owned by owner (Def or Impl).

Source

pub fn generic_params_for_def(&self, def_index: u32) -> GenericParamIter<'_> ⓘ

Binary-searches all GenericParamEntry declarations owned by DefEntry def_index.

Source

pub fn generic_params_for_impl(&self, impl_index: u32) -> GenericParamIter<'_> ⓘ

Binary-searches all GenericParamEntry declarations owned by ImplEntry impl_index.

Source

pub fn where_preds(&self) -> &[WherePredEntry]

Raw slice of sorted WherePredEntry records in this shard (empty for format < v5).

Source

pub fn where_preds_for_owner(&self, owner: GenericOwner) -> WherePredIter<'_> ⓘ

Binary-searches all WherePredEntry bounds/predicates owned by owner (Def or Impl).

Source

pub fn where_preds_for_def(&self, def_index: u32) -> WherePredIter<'_> ⓘ

Binary-searches all WherePredEntry bounds/predicates owned by DefEntry def_index.

Source

pub fn where_preds_for_impl(&self, impl_index: u32) -> WherePredIter<'_> ⓘ

Binary-searches all WherePredEntry bounds/predicates owned by ImplEntry impl_index.

Source

pub fn lang_items(&self) -> &[LangItemEntry]

Raw slice of LangItemEntry records sorted by kind (empty for v3/v4 shards).

Source

pub fn lang_items_iter(&self) -> LangItemIter<'_> ⓘ

Zero-allocation iterator over all LangItemEntry records in this shard.

Source

pub fn lang_item(&self, kind: LangItemKind) -> Option<LangItemView>

Binary-searches the LangItemEntry for kind in this shard.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn uses(&self) -> &[UseEntry]

Raw slice of UseEntry records sorted by (owner_raw, kind_bucket, name_bytes, ...) (empty for v3/v4 shards).

Source

pub fn uses_iter(&self) -> UseIter<'_> ⓘ

Zero-allocation iterator over all UseEntry records in this shard.

Source

pub fn uses_for_owner(&self, owner: UseOwner) -> UseIter<'_> ⓘ

Binary-searches all UseEntry rows (named, glob, and _ trait imports) owned by owner.

Source

pub fn uses_for_crate_root(&self) -> UseIter<'_> ⓘ

Binary-searches all UseEntry rows owned by the crate root (UseOwner::CrateRoot).

Source

pub fn uses_for_def(&self, def_index: u32) -> UseIter<'_> ⓘ

Binary-searches all UseEntry rows owned by DefEntry def_index (UseOwner::Def(def_index)).

Source

pub fn use_by_name(&self, owner: UseOwner, name: &str) -> Option<UseView<'_>>

Binary-searches a named UseEntry (!is_glob && !is_underscore) in owner by identifier name in O(log N).

Source

pub fn glob_uses_for_owner(&self, owner: UseOwner) -> UseIter<'_> ⓘ

Binary-searches all glob imports/re-exports (use path::*;) owned by owner.

Source

pub fn underscore_uses_for_owner(&self, owner: UseOwner) -> UseIter<'_> ⓘ

Binary-searches all anonymous trait imports (use Trait as _;) owned by owner.

Source

pub fn prelude_use(&self) -> Option<UseView<'_>>

Returns the crate’s active #[prelude_import] glob UseView (if present).

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn find_deref_targets(&self, source: &str) -> Vec<&str>

Look up all direct Deref or supertrait targets for a canonical type path.

Source

pub fn find_deref_target(&self, source: &str) -> Option<&str>

Look up the first direct Deref target for a canonical type path.

Source

pub fn resolve_deref_chain(&self, source: &str, max_depth: usize) -> Vec<&str>

Resolves the autoderef/supertrait chain starting from source up to max_depth steps.

Returns the sequence of target type canonical paths (excluding source). Handles multiple supertraits and cycles gracefully via breadth-first search and visited tracking.

Source

pub fn search_symbols(&self, query: &str) -> Vec<&DefEntry>

Fast symbol search across definitions matching a query string.

For ASCII queries, this avoids per-entry heap allocations by lowercasing the query once and performing case-insensitive byte matching directly over string pool slices.

Source

pub fn search_symbols_ascii(&self, needle_lower: &[u8]) -> Vec<&DefEntry>

Fast ASCII case-insensitive symbol search across definitions using a pre-lowercased query slice.

Source

pub fn for_each_symbol_ascii<F>( &self, needle_lower: &[u8], budget: &mut usize, cb: F, ) -> bool
where F: FnMut(&DefEntry) -> bool,

Iterates over matching definitions without heap allocation, stopping when cb returns false or when budget is exhausted.

Source

pub fn for_each_symbol_ascii_budgeted<F>( &self, needle_lower: &[u8], match_budget: &mut usize, record_budget: &mut usize, cb: F, ) -> bool
where F: FnMut(&DefEntry) -> bool,

Iterates over matching definitions without heap allocation, stopping when cb returns false, when match budget is exhausted, or when record_budget of inspected definitions is reached.

Source§

impl IndexReader<Mmap>

Source

pub fn open(path: impl AsRef<Path>) -> Result<IndexReader<Mmap>>

Opens and memory-maps a .ridx file from disk.

Source§

impl<B: AsRef<[u8]>> IndexReader<B>

Source

pub fn from_buffer(buffer: B) -> Result<Self>

Wraps any byte buffer as an IndexReader.

Source

pub fn header(&self) -> &Header

Source

pub fn crate_name(&self) -> &str

Crate name stored in the index.

Source

pub fn crate_version(&self) -> &str

Crate version stored in the index.

Source

pub fn unit_key(&self) -> &str

Compilation unit key stored in the index (or empty string if none).

Source

pub fn generation(&self) -> &str

Source snapshot generation digest stored in the index (or empty string if none).

Source

pub fn target_unit(&self, r: &RefEntry) -> &str

Target compilation unit key for a reference (or empty string if none).

Source

pub fn get_str(&self, offset: u32) -> &str

Retrieves an interned null-terminated string at the specified offset.

Source

pub fn get_file(&self, file_id: u32) -> &str

Returns the file path for a given file_id.

Source

pub fn file_source_hash(&self, file_id: u32) -> u64

Returns the compiled source text hash for a given file_id embedded directly in this index.

Source

pub fn embedded_file_hashes(&self) -> HashMap<String, u64>

Returns all source file provenance hashes embedded directly inside this index shard.

Source

pub fn files_count(&self) -> u32

Total count of source files in the index.

Source

pub fn definitions(&self) -> &[DefEntry]

Slice of all definitions in the index.

Source

pub fn references(&self) -> &[RefEntry]

Slice of all references in the index (sorted by source span).

Source

pub fn types(&self) -> &[TypeEntry]

Slice of all expression types in the index (sorted by source span).

Source

pub fn defs_by_owner(&self) -> &[OwnerIndexEntry]

Slice of all definitions-by-owner entries in the index (sorted by owner hash).

Source

pub fn deref_entries(&self) -> &[DerefEntry]

Slice of all deref entries in the index (sorted by source_type_hash).

Trait Implementations§

Source§

impl<B: Debug> Debug for IndexReader<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Forget for IndexReader<B>

§

impl<B> Freeze for IndexReader<B>
where B: Freeze,

§

impl<B> Move for IndexReader<B>

§

impl<B> RefUnwindSafe for IndexReader<B>
where B: RefUnwindSafe,

§

impl<B> Send for IndexReader<B>
where B: Send,

§

impl<B> Sync for IndexReader<B>
where B: Sync,

§

impl<B> Unpin for IndexReader<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for IndexReader<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for IndexReader<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.