Struct ethers_solc::cache::SolFilesCache
source · 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§
source§impl SolFilesCache
impl SolFilesCache
sourcepub fn new(files: BTreeMap<PathBuf, CacheEntry>, paths: ProjectPaths) -> Self
pub fn new(files: BTreeMap<PathBuf, CacheEntry>, paths: ProjectPaths) -> Self
Create a new cache instance with the given files
pub fn is_empty(&self) -> bool
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many entries the cache contains where each entry represents a sourc file
sourcepub fn artifacts_len(&self) -> usize
pub fn artifacts_len(&self) -> usize
How many Artifacts
this cache references, where a source file can have multiple artifacts
sourcepub fn entries(&self) -> impl Iterator<Item = &CacheEntry>
pub fn entries(&self) -> impl Iterator<Item = &CacheEntry>
Returns an iterator over all CacheEntry
this cache contains
sourcepub fn entry(&self, file: impl AsRef<Path>) -> Option<&CacheEntry>
pub fn entry(&self, file: impl AsRef<Path>) -> Option<&CacheEntry>
Returns the corresponding CacheEntry
for the file if it exists
sourcepub fn entry_mut(&mut self, file: impl AsRef<Path>) -> Option<&mut CacheEntry>
pub fn entry_mut(&mut self, file: impl AsRef<Path>) -> Option<&mut CacheEntry>
Returns the corresponding CacheEntry
for the file if it exists
sourcepub fn read(path: impl AsRef<Path>) -> Result<Self>
pub fn read(path: impl AsRef<Path>) -> Result<Self>
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());
sourcepub fn read_joined(paths: &ProjectPathsConfig) -> Result<Self>
pub fn read_joined(paths: &ProjectPathsConfig) -> Result<Self>
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();
sourcepub fn write(&self, path: impl AsRef<Path>) -> Result<()>
pub fn write(&self, path: impl AsRef<Path>) -> Result<()>
Write the cache as json file to the given path
sourcepub fn join_entries(&mut self, root: impl AsRef<Path>) -> &mut Self
pub fn join_entries(&mut self, root: impl AsRef<Path>) -> &mut Self
Sets the CacheEntry
’s file paths to root
adjoined to self.file
.
sourcepub fn strip_entries_prefix(&mut self, base: impl AsRef<Path>) -> &mut Self
pub fn strip_entries_prefix(&mut self, base: impl AsRef<Path>) -> &mut Self
Removes base
from all CacheEntry
paths
sourcepub fn join_artifacts_files(&mut self, base: impl AsRef<Path>) -> &mut Self
pub fn join_artifacts_files(&mut self, base: impl AsRef<Path>) -> &mut Self
Sets the artifact files location to base
adjoined to the CachEntries
artifacts.
sourcepub fn strip_artifact_files_prefixes(
&mut self,
base: impl AsRef<Path>
) -> &mut Self
pub fn strip_artifact_files_prefixes(
&mut self,
base: impl AsRef<Path>
) -> &mut Self
Removes base
from all artifact file paths
sourcepub fn remove_missing_files(&mut self)
pub fn remove_missing_files(&mut self)
Removes all CacheEntry
which source files don’t exist on disk
NOTE: this assumes the files
are absolute
sourcepub fn all_artifacts_exist(&self) -> bool
pub fn all_artifacts_exist(&self) -> bool
Checks if all artifact files exist
sourcepub fn with_stripped_file_prefixes(self, base: impl AsRef<Path>) -> Self
pub fn with_stripped_file_prefixes(self, base: impl AsRef<Path>) -> Self
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()
sourcepub fn find_artifact_path(
&self,
contract_file: impl AsRef<Path>,
contract_name: impl AsRef<str>
) -> Option<&PathBuf>
pub fn find_artifact_path(
&self,
contract_file: impl AsRef<Path>,
contract_name: impl AsRef<str>
) -> Option<&PathBuf>
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");
sourcepub fn read_artifact<Artifact: DeserializeOwned>(
&self,
contract_file: impl AsRef<Path>,
contract_name: impl AsRef<str>
) -> Result<Artifact>
pub fn read_artifact<Artifact: DeserializeOwned>(
&self,
contract_file: impl AsRef<Path>,
contract_name: impl AsRef<str>
) -> Result<Artifact>
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 [``]
sourcepub fn read_artifacts<Artifact: DeserializeOwned + Send + Sync>(
&self
) -> Result<Artifacts<Artifact>>
pub fn read_artifacts<Artifact: DeserializeOwned + Send + Sync>(
&self
) -> Result<Artifacts<Artifact>>
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();
sourcepub fn retain<'a, I, V>(&mut self, files: I)where
I: IntoIterator<Item = (&'a Path, V)>,
V: IntoIterator<Item = &'a Version>,
pub fn retain<'a, I, V>(&mut self, files: I)where
I: IntoIterator<Item = (&'a Path, V)>,
V: IntoIterator<Item = &'a Version>,
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.
sourcepub fn extend<I>(&mut self, entries: I)where
I: IntoIterator<Item = (PathBuf, CacheEntry)>,
pub fn extend<I>(&mut self, entries: I)where
I: IntoIterator<Item = (PathBuf, CacheEntry)>,
Inserts the provided cache entries, if there is an existing CacheEntry
it will be updated
but versions will be merged.
Trait Implementations§
source§impl Clone for SolFilesCache
impl Clone for SolFilesCache
source§fn clone(&self) -> SolFilesCache
fn clone(&self) -> SolFilesCache
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SolFilesCache
impl Debug for SolFilesCache
source§impl Default for SolFilesCache
impl Default for SolFilesCache
source§impl<'de> Deserialize<'de> for SolFilesCache
impl<'de> Deserialize<'de> for SolFilesCache
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<'a> From<&'a ProjectPathsConfig> for SolFilesCache
impl<'a> From<&'a ProjectPathsConfig> for SolFilesCache
source§fn from(config: &'a ProjectPathsConfig) -> Self
fn from(config: &'a ProjectPathsConfig) -> Self
source§impl PartialEq<SolFilesCache> for SolFilesCache
impl PartialEq<SolFilesCache> for SolFilesCache
source§fn eq(&self, other: &SolFilesCache) -> bool
fn eq(&self, other: &SolFilesCache) -> bool
source§impl Serialize for SolFilesCache
impl Serialize for SolFilesCache
impl Eq for SolFilesCache
impl StructuralEq for SolFilesCache
impl StructuralPartialEq for SolFilesCache
Auto Trait Implementations§
impl RefUnwindSafe for SolFilesCache
impl Send for SolFilesCache
impl Sync for SolFilesCache
impl Unpin for SolFilesCache
impl UnwindSafe for SolFilesCache
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.