pub struct FileResolver<'a> { /* private fields */ }Expand description
Performs file resolution by applying import paths and mappings.
Implementations§
Source§impl<'a> FileResolver<'a>
impl<'a> FileResolver<'a>
Sourcepub fn configure_from_sess(&mut self, sess: &Session)
pub fn configure_from_sess(&mut self, sess: &Session)
Configures the file resolver from a session.
Sourcepub fn configure_from_opts(&mut self, opts: &CompileOpts)
pub fn configure_from_opts(&mut self, opts: &CompileOpts)
Configures the file resolver from compiler options.
Relative base and include paths are relative to the current directory.
Sourcepub fn set_current_dir(&mut self, current_dir: &Path)
pub fn set_current_dir(&mut self, current_dir: &Path)
Sourcepub fn set_base_path(&mut self, base_path: &Path)
pub fn set_base_path(&mut self, base_path: &Path)
Sourcepub fn add_include_paths(&mut self, paths: impl IntoIterator<Item = PathBuf>)
pub fn add_include_paths(&mut self, paths: impl IntoIterator<Item = PathBuf>)
Adds include paths.
Relative paths are relative to the current directory.
Sourcepub fn add_include_path(&mut self, path: PathBuf)
pub fn add_include_path(&mut self, path: PathBuf)
Adds an include path.
Relative paths are relative to the current directory.
Sourcepub fn add_import_remappings(
&mut self,
remappings: impl IntoIterator<Item = ImportRemapping>,
)
pub fn add_import_remappings( &mut self, remappings: impl IntoIterator<Item = ImportRemapping>, )
Adds import remappings.
Sourcepub fn add_import_remapping(&mut self, remapping: ImportRemapping)
pub fn add_import_remapping(&mut self, remapping: ImportRemapping)
Adds an import remapping.
Sourcepub fn source_map(&self) -> &'a SourceMap
pub fn source_map(&self) -> &'a SourceMap
Returns the source map.
Sourcepub fn current_dir(&self) -> &Path
pub fn current_dir(&self) -> &Path
Returns the current directory, or . if it could not be resolved.
Sourcepub fn try_current_dir(&self) -> Option<&Path>
pub fn try_current_dir(&self) -> Option<&Path>
Returns the current directory, if resolved successfully.
Sourcepub fn try_base_path(&self) -> Option<&Path>
pub fn try_base_path(&self) -> Option<&Path>
Returns the base path for import resolution, which defaults to the current directory.
Sourcepub fn canonicalize(&self, path: &Path) -> Result<PathBuf>
pub fn canonicalize(&self, path: &Path) -> Result<PathBuf>
Canonicalizes a path using Self::current_dir.
Sourcepub fn normalize<'b>(&self, path: &'b Path) -> Cow<'b, Path>
pub fn normalize<'b>(&self, path: &'b Path) -> Cow<'b, Path>
Normalizes a path, removing . segments and applying .. segments lexically.
Does not perform I/O.
Sourcepub fn make_absolute<'b>(&self, path: &'b Path) -> Cow<'b, Path>
pub fn make_absolute<'b>(&self, path: &'b Path) -> Cow<'b, Path>
Makes the path absolute by joining it with the current directory.
Does not perform I/O.
Sourcepub fn candidate_paths(
&self,
path: &Path,
parent: Option<&Path>,
) -> Vec<PathBuf>
pub fn candidate_paths( &self, path: &Path, parent: Option<&Path>, ) -> Vec<PathBuf>
Returns the normalized filesystem paths that may satisfy path, in resolution order.
This does not perform I/O or consult the source map. A returned path may remain relative if
the resolver has no current directory. Use Self::resolve_file for exact resolution,
including preloaded source-unit names and ambiguity detection.
Sourcepub fn remap_import_path<'b>(
&self,
path: &'b Path,
parent: Option<&Path>,
) -> Cow<'b, Path>
pub fn remap_import_path<'b>( &self, path: &'b Path, parent: Option<&Path>, ) -> Cow<'b, Path>
Applies import remappings in the context of the source unit name of parent.
Sourcepub fn resolve_file(
&self,
path: &Path,
parent: Option<&Path>,
) -> Result<Arc<SourceFile>, ResolveError>
pub fn resolve_file( &self, path: &Path, parent: Option<&Path>, ) -> Result<Arc<SourceFile>, ResolveError>
Resolves an import path.
parent is the path of the file that contains the import. Pass an empty path for a source
without one, like standard input. Without a parent, path is loaded directly, like a path
on the command line, relative to the current directory.
Sourcepub fn remap_path<'b>(
&self,
path: &'b Path,
parent: Option<&Path>,
) -> Cow<'b, Path>
pub fn remap_path<'b>( &self, path: &'b Path, parent: Option<&Path>, ) -> Cow<'b, Path>
Applies the import path mappings to path.
Sourcepub fn load_stdin(&self) -> Result<Arc<SourceFile>, ResolveError>
pub fn load_stdin(&self) -> Result<Arc<SourceFile>, ResolveError>
Loads stdin into the source map.
Sourcepub fn get_file(&self, path: &Path) -> Option<Arc<SourceFile>>
pub fn get_file(&self, path: &Path) -> Option<Arc<SourceFile>>
Returns the source file with the given path, if it exists, without loading it.
Sourcepub fn try_file(
&self,
path: &Path,
) -> Result<Option<Arc<SourceFile>>, ResolveError>
pub fn try_file( &self, path: &Path, ) -> Result<Option<Arc<SourceFile>>, ResolveError>
Loads path into the source map. Returns None if the file doesn’t exist.
Relative paths are relative to the current directory.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !Freeze for FileResolver<'a>
impl<'a> !RefUnwindSafe for FileResolver<'a>
impl<'a> !UnwindSafe for FileResolver<'a>
impl<'a> Send for FileResolver<'a>
impl<'a> Sync for FileResolver<'a>
impl<'a> Unpin for FileResolver<'a>
impl<'a> UnsafeUnpin for FileResolver<'a>
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
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 152 bytes