Struct Cargo

Source
pub struct Cargo(/* private fields */);
Expand description

The Cargo struct serves as a utility for interacting with Cargo-specific environment variables and commands.

Implementations§

Source§

impl Cargo

Source

pub fn rerun_if_changed(path: impl AsRef<Path>)

Specifies to Cargo that a build script should be re-run if the specified file changes.

Source

pub fn rerun_if_env_changed(env: impl AsRef<str>)

Specifies to Cargo that a build script should be re-run if the specified environment variable changes.

Source

pub fn warning(message: impl AsRef<str>)

Prints a warning message during the build process.

Source

pub fn metadata(key: impl AsRef<str>, value: impl AsRef<str>)

Sets metadata that can be accessed by downstream tools or build scripts.

Source

pub fn binary_executable_path( binary_name: impl AsRef<str>, ) -> Result<PathBuf, VarError>

Fetches the path to the binary executable for a specified binary name from the environment variables.

Source

pub fn is_primary_package() -> bool

Checks if the package being built is the primary package.

Source

pub fn binary_path() -> Result<PathBuf, VarError>

Path to the cargo binary performing the build

Source

pub fn manifest_dir() -> Result<PathBuf, VarError>

The directory containing the manifest of your package

Source

pub fn manifest_path() -> Result<PathBuf, VarError>

The path to the manifest of your package

Source

pub fn pkg_version() -> Result<String, VarError>

The full version of your package

Source

pub fn pkg_version_major() -> Result<String, VarError>

The major version of your package

Source

pub fn pkg_version_minor() -> Result<String, VarError>

The minor version of your package

Source

pub fn pkg_version_patch() -> Result<String, VarError>

The patch version of your package

Source

pub fn pkg_version_pre() -> Result<String, VarError>

The pre-release version of your package

Source

pub fn pkg_authors() -> Result<String, VarError>

Colon separated list of authors from the manifest of your package

Source

pub fn pkg_name() -> Result<String, VarError>

The name of your package

Source

pub fn pkg_description() -> Result<String, VarError>

The description from the manifest of your package

Source

pub fn pkg_homepage() -> Result<String, VarError>

The home page from the manifest of your package

Source

pub fn pkg_repository() -> Result<String, VarError>

The repository from the manifest of your package

Source

pub fn pkg_license() -> Result<String, VarError>

The license from the manifest of your package

Source

pub fn pkg_license_file() -> Result<PathBuf, VarError>

The license file from the manifest of your package

Source

pub fn pkg_rust_version() -> Result<String, VarError>

The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version

Source

pub fn pkg_readme() -> Result<PathBuf, VarError>

Path to the README file of your package

Source

pub fn crate_name() -> Result<String, VarError>

The name of the crate that is currently being compiled. It is the name of the Cargo target with - converted to _, such as the name of the library, binary, example, integration test, or benchmark

Source

pub fn bin_name() -> Result<String, VarError>

The name of the binary that is currently being compiled. Only set for binaries or binary examples. This name does not include any file extension, such as .exe

Source

pub fn out_dir() -> Result<PathBuf, VarError>

If the package has a build script, this is set to the folder where the build script should place its output. See below for more information. (Only set during compilation.)

Source

pub fn target_tmpdir() -> Result<PathBuf, VarError>

Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn’t manage its content in any way, this is the responsibility of the test code

Source

pub fn rustc_current_dir() -> Result<PathBuf, VarError>

This is a path that rustc is invoked from (nightly only)

Auto Trait Implementations§

§

impl Freeze for Cargo

§

impl RefUnwindSafe for Cargo

§

impl Send for Cargo

§

impl Sync for Cargo

§

impl Unpin for Cargo

§

impl UnwindSafe for Cargo

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.