foundry_compilers::compilers

Trait ParsedSource

source
pub trait ParsedSource:
    Debug
    + Sized
    + Send
    + Clone {
    type Language: Language;

    // Required methods
    fn parse(content: &str, file: &Path) -> Result<Self>;
    fn version_req(&self) -> Option<&VersionReq>;
    fn resolve_imports<C>(
        &self,
        paths: &ProjectPathsConfig<C>,
        include_paths: &mut BTreeSet<PathBuf>,
    ) -> Result<Vec<PathBuf>>;
    fn language(&self) -> Self::Language;

    // Provided method
    fn compilation_dependencies<'a>(
        &self,
        _imported_nodes: impl Iterator<Item = (&'a Path, &'a Self)>,
    ) -> impl Iterator<Item = &'a Path>
       where Self: 'a { ... }
}
Expand description

Parser of the source files which is used to identify imports and version requirements of the given source.

Used by path resolver to resolve imports or determine compiler versions needed to compiler given sources.

Required Associated Types§

Required Methods§

source

fn parse(content: &str, file: &Path) -> Result<Self>

source

fn version_req(&self) -> Option<&VersionReq>

source

fn resolve_imports<C>( &self, paths: &ProjectPathsConfig<C>, include_paths: &mut BTreeSet<PathBuf>, ) -> Result<Vec<PathBuf>>

Invoked during import resolution. Should resolve imports for the given source, and populate include_paths for compilers which support this config.

source

fn language(&self) -> Self::Language

Provided Methods§

source

fn compilation_dependencies<'a>( &self, _imported_nodes: impl Iterator<Item = (&'a Path, &'a Self)>, ) -> impl Iterator<Item = &'a Path>
where Self: 'a,

Used to configure OutputSelection for sparse builds. In certain cases, we might want to include some of the file dependencies into the compiler output even if we might not be directly interested in them.

Example of such case is when we are compiling Solidity file containing link references and need them to be included in the output to deploy needed libraries.

Receives iterator over imports of the current source.

Returns iterator over paths to the files that should be compiled with full output selection.

Object Safety§

This trait is not object safe.

Implementors§