Struct cargo_toml::Package

source ·
#[non_exhaustive]
pub struct Package<Metadata = Value> {
Show 27 fields pub name: String, pub edition: Inheritable<Edition>, pub rust_version: Option<Inheritable<String>>, pub version: Inheritable<String>, pub build: Option<OptionalFile>, pub workspace: Option<String>, pub authors: Inheritable<Vec<String>>, pub links: Option<String>, pub description: Option<Inheritable<String>>, pub homepage: Option<Inheritable<String>>, pub documentation: Option<Inheritable<String>>, pub readme: Inheritable<OptionalFile>, pub keywords: Inheritable<Vec<String>>, pub categories: Inheritable<Vec<String>>, pub exclude: Inheritable<Vec<String>>, pub include: Inheritable<Vec<String>>, pub license: Option<Inheritable<String>>, pub license_file: Option<Inheritable<PathBuf>>, pub repository: Option<Inheritable<String>>, pub default_run: Option<String>, pub autobins: bool, pub autoexamples: bool, pub autotests: bool, pub autobenches: bool, pub publish: Inheritable<Publish>, pub resolver: Option<Resolver>, pub metadata: Option<Metadata>,
}
Expand description

The [package] section of the Manifest. This is where crate properties are.

Note that most of these properties can be inherited from a workspace, and therefore not available just from reading a single Cargo.toml. See Manifest::inherit_workspace.

You can replace Metadata generic type with your own to parse into something more useful than a generic toml Value

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

Careful: some names are uppercase, case-sensitive. - changes to _ when used as a Rust identifier.

§edition: Inheritable<Edition>

Package’s edition opt-in.

§rust_version: Option<Inheritable<String>>

MSRV 1.x (beware: does not require semver formatting)

§version: Inheritable<String>

Must parse as semver, e.g. “1.9.0”

§build: Option<OptionalFile>

Build script definition

§workspace: Option<String>

Workspace this package is a member of (None if it’s implicit)

§authors: Inheritable<Vec<String>>

e.g. [“Author e@mail”, “etc”] Deprecated.

§links: Option<String>

It doesn’t link to anything

§description: Option<Inheritable<String>>

A short blurb about the package. This is not rendered in any format when uploaded to crates.io (aka this is not markdown).

§homepage: Option<Inheritable<String>>

Project’s homepage

§documentation: Option<Inheritable<String>>

Path to your custom docs. Unnecssary if you rely on docs.rs.

§readme: Inheritable<OptionalFile>

This points to a file under the package root (relative to this Cargo.toml). implied if README.md, README.txt or README exists.

§keywords: Inheritable<Vec<String>>

Up to 5, for search

§categories: Inheritable<Vec<String>>

This is a list of up to five categories where this crate would fit. e.g. [“command-line-utilities”, “development-tools::cargo-plugins”]

§exclude: Inheritable<Vec<String>>

Don’t publish these files

§include: Inheritable<Vec<String>>

Publish these files

§license: Option<Inheritable<String>>

e.g. “MIT”

§license_file: Option<Inheritable<PathBuf>>

If license is not standard

§repository: Option<Inheritable<String>>

(HTTPS) URL to crate’s repository

§default_run: Option<String>

The default binary to run by cargo run.

§autobins: bool

Discover binaries from the file system

§autoexamples: bool

Discover examples from the file system

§autotests: bool

Discover tests from the file system

§autobenches: bool

Discover benchmarks from the file system

§publish: Inheritable<Publish>

Disable publishing or select custom registries.

§resolver: Option<Resolver>

“2” is the only useful value

§metadata: Option<Metadata>

Arbitrary metadata of any type, an extension point for 3rd party tools.

Implementations§

source§

impl<Metadata> Package<Metadata>

source

pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self

Prefer creating it by parsing a Manifest instead.

source

pub fn authors(&self) -> &[String]

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn categories(&self) -> &[String]

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn categories_mut(&mut self) -> &mut Vec<String>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn description(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn set_description(&mut self, description: Option<String>)

source

pub fn documentation(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn set_documentation(&mut self, documentation: Option<String>)

source

pub fn edition(&self) -> Edition

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn exclude(&self) -> &[String]

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn include(&self) -> &[String]

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn homepage(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn set_homepage(&mut self, homepage: Option<String>)

source

pub fn keywords(&self) -> &[String]

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn license(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn license_file(&self) -> Option<&Path>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn publish(&self) -> &Publish

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn readme(&self) -> &OptionalFile

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn repository(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn set_repository(&mut self, repository: Option<String>)

source

pub fn rust_version(&self) -> Option<&str>

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

source

pub fn version(&self) -> &str

Panics if the field is not available (inherited from a workspace that hasn’t been loaded)

The property that doesn’t actually link with anything.

Can’t be inherited.

source

pub fn name(&self) -> &str

Name of the package/crate. Libraries and binaries can override it.

Can’t be inherited.

Trait Implementations§

source§

impl<Metadata: Clone> Clone for Package<Metadata>

source§

fn clone(&self) -> Package<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 Package<Metadata>

source§

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

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

impl<Metadata: Default> Default for Package<Metadata>

source§

fn default() -> Self

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

impl<'de, Metadata> Deserialize<'de> for Package<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 Package<Metadata>

source§

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

source§

impl<Metadata> StructuralPartialEq for Package<Metadata>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<Metadata> UnwindSafe for Package<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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>,