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

source

pub fn new(files: BTreeMap<PathBuf, CacheEntry>, paths: ProjectPaths) -> Self

Create a new cache instance with the given files

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

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

source

pub fn artifacts_len(&self) -> usize

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

source

pub fn entries(&self) -> impl Iterator<Item = &CacheEntry>

Returns an iterator over all CacheEntry this cache contains

source

pub fn entry(&self, file: impl AsRef<Path>) -> Option<&CacheEntry>

Returns the corresponding CacheEntry for the file if it exists

source

pub fn entry_mut(&mut self, file: impl AsRef<Path>) -> Option<&mut CacheEntry>

Returns the corresponding CacheEntry for the file if it exists

source

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());
source

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();
source

pub fn write(&self, path: impl AsRef<Path>) -> Result<()>

Write the cache as json file to the given path

source

pub fn join_entries(&mut self, root: impl AsRef<Path>) -> &mut Self

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

source

pub fn strip_entries_prefix(&mut self, base: impl AsRef<Path>) -> &mut Self

Removes base from all CacheEntry paths

source

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.

source

pub fn strip_artifact_files_prefixes( &mut self, base: impl AsRef<Path> ) -> &mut Self

Removes base from all artifact file paths

source

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

source

pub fn all_artifacts_exist(&self) -> bool

Checks if all artifact files exist

source

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()

source

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");
source

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 [``]

source

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();
source

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.

source

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.

source§

impl SolFilesCache

source

pub async fn async_read(path: impl AsRef<Path>) -> Result<Self>

Available on crate feature async only.
source

pub async fn async_write(&self, path: impl AsRef<Path>) -> Result<()>

Available on crate feature async only.

Trait Implementations§

source§

impl Clone for SolFilesCache

source§

fn clone(&self) -> SolFilesCache

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SolFilesCache

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for SolFilesCache

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for SolFilesCache

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a> From<&'a ProjectPathsConfig> for SolFilesCache

source§

fn from(config: &'a ProjectPathsConfig) -> Self

Converts to this type from the input type.
source§

impl PartialEq for SolFilesCache

source§

fn eq(&self, other: &SolFilesCache) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for SolFilesCache

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for SolFilesCache

source§

impl StructuralPartialEq for SolFilesCache

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> JsonSchemaMaybe for T