Struct ethers_core::macros::ProjectEnvironment
source · pub struct ProjectEnvironment { /* private fields */ }
Expand description
Represents a generic Rust/Cargo project’s environment.
Implementations§
source§impl ProjectEnvironment
impl ProjectEnvironment
pub fn new<T: Into<PathBuf>, U: Into<String>>( manifest_dir: T, crate_name: U ) -> Self
pub fn new_from_env() -> Option<Self>
sourcepub fn determine_ethers_crates(
&self
) -> Option<HashMap<EthersCrate, &'static str>>
pub fn determine_ethers_crates( &self ) -> Option<HashMap<EthersCrate, &'static str>>
Determines the crate paths to use by looking at the metadata of the project.
The names will be:
ethers::*
ifethers
is a dependency for all crates;- for each
crate
:ethers_<crate>
if it is a dependency, otherwiseethers::<crate>
.
pub fn crate_names_from_metadata( &self ) -> Option<HashMap<EthersCrate, &'static str>>
sourcepub fn is_crate_root(&self) -> bool
pub fn is_crate_root(&self) -> bool
Returns whether the crate
path identifier refers to the root package.
This is false for integration tests, benches, and examples, as the crate
keyword will not
refer to the root package.
We can find this using some environment variables set by Cargo during compilation:
CARGO_TARGET_TMPDIR
is only set when building integration test or benchmark code;- When
CARGO_MANIFEST_DIR
contains/benches/
or/examples/
CARGO_CRATE_NAME
, seeis_crate_name_in_dirs
.
sourcepub fn is_crate_name_in_dirs(&self) -> bool
pub fn is_crate_name_in_dirs(&self) -> bool
Returns whether crate_name
is the name of a file or directory in the first level of
manifest_dir/{benches,examples,tests}/
.
Example
With this project structure:
.
├── Cargo.lock
├── Cargo.toml
├── src/
│ ...
├── benches/
│ ├── large-input.rs
│ └── multi-file-bench/
│ ├── main.rs
│ └── bench_module.rs
├── examples/
│ ├── simple.rs
│ └── multi-file-example/
│ ├── main.rs
│ └── ex_module.rs
└── tests/
├── some-integration-tests.rs
└── multi-file-test/
├── main.rs
└── test_module.rs
The resulting CARGO_CRATE_NAME
values will be:
Path | Value |
---|---|
benches/large-input.rs | large-input |
benches/multi-file-bench/**/*.rs | multi-file-bench |
examples/simple.rs | simple |
examples/multi-file-example/**/*.rs | multi-file-example |
tests/some-integration-tests.rs | some-integration-tests |
tests/multi-file-test/**/*.rs | multi-file-test |
Trait Implementations§
source§impl Clone for ProjectEnvironment
impl Clone for ProjectEnvironment
source§fn clone(&self) -> ProjectEnvironment
fn clone(&self) -> ProjectEnvironment
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ProjectEnvironment
impl Debug for ProjectEnvironment
source§impl PartialEq<ProjectEnvironment> for ProjectEnvironment
impl PartialEq<ProjectEnvironment> for ProjectEnvironment
source§fn eq(&self, other: &ProjectEnvironment) -> bool
fn eq(&self, other: &ProjectEnvironment) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.