pub struct SolFilesCache {
    pub format: String,
    pub paths: ProjectPaths,
    pub files: BTreeMap<PathBuf, CacheEntry>,
}
Expand description

A multi version cache file

Fields§

§format: String§paths: ProjectPaths

contains all directories used for the project

§files: BTreeMap<PathBuf, CacheEntry>

Implementations§

Create a new cache instance with the given files

How many entries the cache contains where each entry represents a sourc file

How many Artifacts this cache references, where a source file can have multiple artifacts

Returns an iterator over all CacheEntry this cache contains

Returns the corresponding CacheEntry for the file if it exists

Returns the corresponding CacheEntry for the file if it exists

Reads the cache json file from the given path

See also Self::read_joined()

Errors

If the cache file does not exist

Example
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;

let project = Project::builder().build().unwrap();
let mut cache = SolFilesCache::read(project.cache_path()).unwrap();
cache.join_artifacts_files(project.artifacts_path());

Reads the cache json file from the given path and returns the cache with paths adjoined to the ProjectPathsConfig.

This expects the artifact files to be relative to the artifacts dir of the paths and the CachEntry paths to be relative to the root dir of the paths

Example
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;

let project = Project::builder().build().unwrap();
let cache = SolFilesCache::read_joined(&project.paths).unwrap();

Write the cache as json file to the given path

Sets the CacheEntry’s file paths to root adjoined to self.file.

Removes base from all CacheEntry paths

Sets the artifact files location to base adjoined to the CachEntries artifacts.

Removes base from all artifact file paths

Removes all CacheEntry which source files don’t exist on disk

NOTE: this assumes the files are absolute

Checks if all artifact files exist

Strips the given prefix from all file paths that identify a CacheEntry to make them relative to the given base argument

In other words this sets the keys (the file path of a solidity file) relative to the base argument, so that the key /Users/me/project/src/Greeter.sol will be changed to src/Greeter.sol if base is /Users/me/project

Example
use ethers_solc::artifacts::contract::CompactContract;
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;
let project = Project::builder().build().unwrap();
let cache = SolFilesCache::read(project.cache_path())
    .unwrap()
    .with_stripped_file_prefixes(project.root());
let artifact: CompactContract = cache.read_artifact("src/Greeter.sol", "Greeter").unwrap();

Note: this only affects the source files, see Self::strip_artifact_files_prefixes()

Returns the path to the artifact of the given (file, contract) pair

Example
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;

let project = Project::builder().build().unwrap();
let cache = SolFilesCache::read_joined(&project.paths).unwrap();
cache.find_artifact_path("/Users/git/myproject/src/Greeter.sol", "Greeter");

Finds the path to the artifact of the given (file, contract) pair, see Self::find_artifact_path(), and reads the artifact as json file

Example
fn t() {
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;
use ethers_solc::artifacts::contract::CompactContract;

let project = Project::builder().build().unwrap();
let cache = SolFilesCache::read_joined(&project.paths).unwrap();
let artifact: CompactContract = cache.read_artifact("/Users/git/myproject/src/Greeter.sol", "Greeter").unwrap();

NOTE: unless the cache’s files keys were modified contract_file is expected to be absolute, see [``]

Reads all cached artifacts from disk using the given ArtifactOutput handler

Example
use ethers_solc::cache::SolFilesCache;
use ethers_solc::Project;
use ethers_solc::artifacts::contract::CompactContractBytecode;
let project = Project::builder().build().unwrap();
let cache = SolFilesCache::read_joined(&project.paths).unwrap();
let artifacts = cache.read_artifacts::<CompactContractBytecode>().unwrap();

Retains only the CacheEntry specified by the file + version combination.

In other words, only keep those cache entries with the paths (keys) that the iterator yields and only keep the versions in the cache entry that the version iterator yields.

Inserts the provided cache entries, if there is an existing CacheEntry it will be updated but versions will be merged.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

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

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more