pub struct ProjectEnvironment { /* private fields */ }Available on crate feature
macros only.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::*ifethersis 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_TMPDIRis only set when building integration test or benchmark code;- When
CARGO_MANIFEST_DIRcontains/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.rsThe 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 duplicate of the value. Read more
1.0.0 (const: unstable) · 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 for ProjectEnvironment
impl PartialEq for ProjectEnvironment
Source§fn eq(&self, other: &ProjectEnvironment) -> bool
fn eq(&self, other: &ProjectEnvironment) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for ProjectEnvironment
impl StructuralPartialEq for ProjectEnvironment
Auto Trait Implementations§
impl Freeze for ProjectEnvironment
impl RefUnwindSafe for ProjectEnvironment
impl Send for ProjectEnvironment
impl Sync for ProjectEnvironment
impl Unpin for ProjectEnvironment
impl UnsafeUnpin for ProjectEnvironment
impl UnwindSafe for ProjectEnvironment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more