Struct cargo_toml::Manifest

source ·
pub struct Manifest<Metadata = Value> {
Show 16 fields pub package: Option<Package<Metadata>>, pub workspace: Option<Workspace<Metadata>>, pub dependencies: DepsSet, pub dev_dependencies: DepsSet, pub build_dependencies: DepsSet, pub target: TargetDepsSet, pub features: FeatureSet, pub replace: DepsSet, pub patch: PatchSet, pub lib: Option<Product>, pub profile: Profiles, pub badges: Badges, pub bin: Vec<Product>, pub bench: Vec<Product>, pub test: Vec<Product>, pub example: Vec<Product>,
}
Expand description

The top-level Cargo.toml structure. This is the main type in this library.

The Metadata is a generic type for [package.metadata] table. You can replace it with your own struct type if you use the metadata and don’t want to use the catch-all Value type.

Fields§

§package: Option<Package<Metadata>>

Package definition (a cargo crate)

§workspace: Option<Workspace<Metadata>>

Workspace-wide settings

§dependencies: DepsSet

Normal dependencies

§dev_dependencies: DepsSet

Dev/test-only deps

§build_dependencies: DepsSet

Build-time deps

§target: TargetDepsSet

[target.cfg.dependencies]

§features: FeatureSet

[features] section

§replace: DepsSet
👎Deprecated: Cargo recommends patch instead

Obsolete

§patch: PatchSet

[patch.crates-io] section

§lib: Option<Product>

Note that due to autolibs feature this is not the complete list unless you run Manifest::complete_from_path

§profile: Profiles

Compilation/optimization settings

§badges: Badges

[badges] section

§bin: Vec<Product>

Note that due to autobins feature this is not the complete list unless you run Manifest::complete_from_path

§bench: Vec<Product>

Benchmarks

§test: Vec<Product>

Integration tests

§example: Vec<Product>

Examples

Implementations§

source§

impl Manifest<Value>

source

pub fn from_path(cargo_toml_path: impl AsRef<Path>) -> Result<Self, Error>

Parse contents from a Cargo.toml file on disk.

Calls Manifest::complete_from_path to discover implicit binaries, etc. It will search for a workspace.

source

pub fn from_slice(cargo_toml_content: &[u8]) -> Result<Self, Error>

Parse contents of a Cargo.toml file already loaded as a byte slice.

It does not call Manifest::complete_from_path, so may be missing implicit data, and panic if workspace inheritance is used.

source

pub fn from_str(cargo_toml_content: &str) -> Result<Self, Error>

Parse contents of a Cargo.toml file loaded as a string

Note: this is not a file name, but file’s TOML-syntax content. See from_path.

It does not call Manifest::complete_from_path, so may be missing implicit data, and panic if workspace inheritance is used.

source§

impl<Metadata: for<'a> Deserialize<'a>> Manifest<Metadata>

source

pub fn from_slice_with_metadata( cargo_toml_content: &[u8] ) -> Result<Self, Error>

Parse Cargo.toml, and parse its [package.metadata] into a custom Serde-compatible type.

It does not call Manifest::complete_from_path, so may be missing implicit data.

source

pub fn from_path_with_metadata<P: AsRef<Path>>( cargo_toml_path: P ) -> Result<Self, Error>

Parse contents from Cargo.toml file on disk, with custom Serde-compatible metadata type.

Calls Manifest::complete_from_path

source

pub fn complete_from_path(&mut self, path: &Path) -> Result<(), Error>

Cargo.toml doesn’t contain explicit information about [lib] and [[bin]], which are inferred based on files on disk.

This scans the disk to make the data in the manifest as complete as possible.

It supports workspace inheritance and will search for a root workspace. Use Manifest::complete_from_path_and_workspace to provide the workspace explicitly.

source

pub fn complete_from_path_and_workspace<PackageMetadataTypeDoesNotMatterHere>( &mut self, package_manifest_path: &Path, workspace_manifest_and_path: Option<(&Manifest<PackageMetadataTypeDoesNotMatterHere>, &Path)> ) -> Result<(), Error>

Manifest::complete_from_path, but allows passing workspace manifest explicitly.

workspace_manifest_and_path is the root workspace manifest already parsed, and the path is the path to the root workspace’s directory. If it’s None, the root workspace will be discovered automatically.

source

pub fn complete_from_abstract_filesystem<PackageMetadataTypeDoesNotMatterHere, Fs: AbstractFilesystem>( &mut self, fs: Fs, workspace_manifest_and_path: Option<(&Manifest<PackageMetadataTypeDoesNotMatterHere>, &Path)> ) -> Result<(), Error>

Cargo.toml doesn’t contain explicit information about [lib] and [[bin]], which are inferred based on files on disk.

You can provide any implementation of directory scan, which doesn’t have to be reading straight from disk (might scan a tarball or a git repo, for example).

If workspace_manifest_and_path is set, it will inherit from this workspace. If it’s None, it will try to find a workspace if needed.

source

pub fn needs_workspace_inheritance(&self) -> bool

If true, some fields are unavailable. If false, it’s fully usable as-is.

It is false in manifests that use workspace inheritance, but had their data completed from the root manifest already.

source

pub fn inherit_workspace<Ignored>( &mut self, workspace_manifest: &Manifest<Ignored>, workspace_base_path: &Path ) -> Result<(), Error>

👎Deprecated: this functionality has been merged into complete_from_path_and_workspace or complete_from_abstract_filesystem

Copy workspace-inheritable properties from the workspace_manifest.

workspace_base_path should be an absolute path to a directory where the workspace manifest is located. Used as a base for readme and license-file.

source

pub fn package(&self) -> &Package<Metadata>

Panics if it’s not a package (only a workspace).

You can access .package field directly to handle the Option.

Trait Implementations§

source§

impl<Metadata: Clone> Clone for Manifest<Metadata>

source§

fn clone(&self) -> Manifest<Metadata>

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<Metadata: Debug> Debug for Manifest<Metadata>

source§

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

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

impl<Metadata: Default> Default for Manifest<Metadata>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, Metadata> Deserialize<'de> for Manifest<Metadata>
where Metadata: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Metadata: PartialEq> PartialEq for Manifest<Metadata>

source§

fn eq(&self, other: &Manifest<Metadata>) -> 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<Metadata> Serialize for Manifest<Metadata>
where Metadata: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Metadata> StructuralPartialEq for Manifest<Metadata>

Auto Trait Implementations§

§

impl<Metadata> RefUnwindSafe for Manifest<Metadata>
where Metadata: RefUnwindSafe,

§

impl<Metadata> Send for Manifest<Metadata>
where Metadata: Send,

§

impl<Metadata> Sync for Manifest<Metadata>
where Metadata: Sync,

§

impl<Metadata> Unpin for Manifest<Metadata>
where Metadata: Unpin,

§

impl<Metadata> UnwindSafe for Manifest<Metadata>
where Metadata: UnwindSafe,

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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,