Struct ethers_core::macros::ProjectEnvironment
source · pub struct ProjectEnvironment { /* private fields */ }
macros
only.Expand description
Represents a generic Rust/Cargo project’s environment.
Implementations§
source§impl ProjectEnvironment
impl ProjectEnvironment
sourcepub fn new<T: Into<PathBuf>, U: Into<String>>(
manifest_dir: T,
crate_name: U
) -> Self
pub fn new<T: Into<PathBuf>, U: Into<String>>( manifest_dir: T, crate_name: U ) -> Self
Creates a new instance using the given manifest dir and crate name.
sourcepub fn new_from_env() -> Option<Self>
pub fn new_from_env() -> Option<Self>
Creates a new instance using the the CARGO_MANIFEST_DIR
and CARGO_CRATE_NAME
environment
variables.
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>
.
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
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ProjectEnvironment
impl Debug for ProjectEnvironment
source§impl PartialEq for ProjectEnvironment
impl PartialEq for ProjectEnvironment
source§fn eq(&self, other: &ProjectEnvironment) -> bool
fn eq(&self, other: &ProjectEnvironment) -> bool
self
and other
values to be equal, and is used
by ==
.