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

source

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.

source

pub fn new_from_env() -> Option<Self>

Creates a new instance using the the CARGO_MANIFEST_DIR and CARGO_CRATE_NAME environment variables.

source

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::* if ethers is a dependency for all crates;
  • for each crate:
    • ethers_<crate> if it is a dependency, otherwise ethers::<crate>.
source

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, see is_crate_name_in_dirs.
source

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:

PathValue
benches/large-input.rslarge-input
benches/multi-file-bench/**/*.rsmulti-file-bench
examples/simple.rssimple
examples/multi-file-example/**/*.rsmulti-file-example
tests/some-integration-tests.rssome-integration-tests
tests/multi-file-test/**/*.rsmulti-file-test

Trait Implementations§

source§

impl Clone for ProjectEnvironment

source§

fn clone(&self) -> ProjectEnvironment

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 ProjectEnvironment

source§

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

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

impl PartialEq for ProjectEnvironment

source§

fn eq(&self, other: &ProjectEnvironment) -> 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 Eq for ProjectEnvironment

source§

impl StructuralPartialEq for ProjectEnvironment

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> JsonSchemaMaybe for T