Struct Package

Source
#[non_exhaustive]
pub struct Package<Metadata = Value> {
Show 28 fields pub name: String, pub version: Inheritable<String>, pub edition: Inheritable<Edition>, pub rust_version: Option<Inheritable<String>>, pub build: Option<OptionalFile>, pub workspace: Option<PathBuf>, 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 autolib: 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.

§version: Inheritable<String>

See the version() getter for more info.

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

This field may have unknown value when using workspace inheritance, and when the Manifest has been loaded without its workspace.

§edition: Inheritable<Edition>

Package’s edition opt-in. Use Package::edition() to read it.

§rust_version: Option<Inheritable<String>>

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

§build: Option<OptionalFile>

Build script definition

§workspace: Option<PathBuf>

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

This may be incorrectly set to true if the crate uses 2015 edition and has explicit [[bin]] sections

§autolib: bool

Discover libraries from the file system

§autoexamples: bool

Discover examples from the file system

This may be incorrectly set to true if the crate uses 2015 edition and has explicit [[example]] sections

§autotests: bool

Discover tests from the file system

This may be incorrectly set to true if the crate uses 2015 edition and has explicit [[test]] sections

§autobenches: bool

Discover benchmarks from the file system

This may be incorrectly set to true if the crate uses 2015 edition and has explicit [[bench]] sections

§publish: Inheritable<Publish>

Disable publishing or select custom registries.

§resolver: Option<Resolver>

The feature resolver version.

§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 version(&self) -> &str

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

Manifest::from_str does not know where the TOML data came from, so it has no way of searching the file system (or tarball or git) for a matching Cargo Workspace Manifest.

Without a workspace, properties that use inheritance are missing data, and therefore can’t be returned, and will panic.

You can access these properties directly, they are an Inheritable enum.

The version will default to 0.0.0 if the version field was absent in the manifest.

Source

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

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

See version for more information.

Source

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

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

See version for more information.

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)

See version for more information.

Source

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

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

See version for more information.

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)

See version for more information.

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)

See version for more information.

Source

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

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

See version for more information.

Source

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

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

See version for more information.

Source

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

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

See version for more information.

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)

See version for more information.

Source

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

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

See version for more information.

Source

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

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

See version for more information.

Source

pub fn publish(&self) -> &Publish

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

See version for more information.

Source

pub fn readme(&self) -> &OptionalFile

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

See version for more information.

Source

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

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

See version for more information.

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)

See version for more information.

Source

pub fn set_rust_version(&mut self, rust_version: Option<String>)

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

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> StructuralPartialEq for Package<Metadata>

Auto Trait Implementations§

§

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

§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,