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 contract_names(&self) -> &[String];
    fn language(&self) -> Self::Language;
    fn resolve_imports<C>(
        &self,
        paths: &ProjectPathsConfig<C>,
        include_paths: &mut BTreeSet<PathBuf>,
    ) -> Result<Vec<PathBuf>>;

    // 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>

Parses the content of the source file.

Source

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

Returns the version requirement of the source.

Source

fn contract_names(&self) -> &[String]

Returns a list of contract names defined in the source.

Source

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

Returns the language of the source.

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.

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§