Skip to main content

FileResolver

Struct FileResolver 

Source
pub struct FileResolver<'a> { /* private fields */ }
Expand description

Performs file resolution by applying import paths and mappings.

Implementations§

Source§

impl<'a> FileResolver<'a>

Source

pub fn new(source_map: &'a SourceMap) -> Self

Creates a new file resolver.

Source

pub fn configure_from_sess(&mut self, sess: &Session)

Configures the file resolver from a session.

Source

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.

Source

pub fn clear(&mut self)

Clears the internal state.

Source

pub fn set_current_dir(&mut self, current_dir: &Path)

Sets the current directory.

§Panics

Panics if current_dir is not an absolute path.

Source

pub fn set_base_path(&mut self, base_path: &Path)

Sets the base path.

§Panics

Panics if base_path is not an absolute path.

Source

pub fn add_include_paths(&mut self, paths: impl IntoIterator<Item = PathBuf>)

Adds include paths.

Relative paths are relative to the current directory.

Source

pub fn add_include_path(&mut self, path: PathBuf)

Adds an include path.

Relative paths are relative to the current directory.

Source

pub fn add_import_remappings( &mut self, remappings: impl IntoIterator<Item = ImportRemapping>, )

Adds import remappings.

Source

pub fn add_import_remapping(&mut self, remapping: ImportRemapping)

Adds an import remapping.

Source

pub fn source_map(&self) -> &'a SourceMap

Returns the source map.

Source

pub fn current_dir(&self) -> &Path

Returns the current directory, or . if it could not be resolved.

Source

pub fn try_current_dir(&self) -> Option<&Path>

Returns the current directory, if resolved successfully.

Source

pub fn try_base_path(&self) -> Option<&Path>

Returns the base path for import resolution, which defaults to the current directory.

Source

pub fn canonicalize(&self, path: &Path) -> Result<PathBuf>

Canonicalizes a path using Self::current_dir.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remap_path<'b>( &self, path: &'b Path, parent: Option<&Path>, ) -> Cow<'b, Path>

Applies the import path mappings to path.

Source

pub fn load_stdin(&self) -> Result<Arc<SourceFile>, ResolveError>

Loads stdin into the source map.

Source

pub fn get_file(&self, path: &Path) -> Option<Arc<SourceFile>>

Returns the source file with the given path, if it exists, without loading it.

Source

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§

Source§

impl<'a> Debug for FileResolver<'a>

Source§

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

Formats the value using the given formatter. Read more

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> 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, R> CollectAndApply<T, R> for T

Source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

Source§

type Output = R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

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