Skip to content

Commit 3b91f14

Browse files
committed
Make Cargo.toml's authors field optional
Per rust-lang/rfcs#3052
1 parent 7d9fe4a commit 3b91f14

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/cargo_toml.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub(crate) struct CargoTomlPackage {
2020
// https://doc.rust-lang.org/cargo/reference/manifest.html#the-package-section
2121
pub(crate) name: String,
2222
pub(crate) version: String,
23-
pub(crate) authors: Vec<String>,
2423
// All other fields are optional
24+
pub(crate) authors: Option<Vec<String>>,
2525
pub(crate) description: Option<String>,
2626
pub(crate) documentation: Option<String>,
2727
pub(crate) homepage: Option<String>,
@@ -200,4 +200,32 @@ mod test {
200200

201201
assert_eq!(cargo_toml.classifiers(), classifiers);
202202
}
203+
204+
#[test]
205+
fn test_metadata_from_cargo_toml_without_authors() {
206+
let cargo_toml = indoc!(
207+
r#"
208+
[package]
209+
name = "info-project"
210+
version = "0.1.0"
211+
description = "A test project"
212+
homepage = "https://example.org"
213+
keywords = ["ffi", "test"]
214+
215+
[lib]
216+
crate-type = ["cdylib"]
217+
name = "pyo3_pure"
218+
219+
[package.metadata.maturin.scripts]
220+
ph = "maturin:print_hello"
221+
222+
[package.metadata.maturin]
223+
classifiers = ["Programming Language :: Python"]
224+
requires-dist = ["flask~=1.1.0", "toml==0.10.0"]
225+
"#
226+
);
227+
228+
let cargo_toml: Result<CargoToml, _> = toml::from_str(&cargo_toml);
229+
assert!(cargo_toml.is_ok());
230+
}
203231
}

src/metadata.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,21 @@ impl Metadata21 {
256256
cargo_toml: &CargoToml,
257257
manifest_path: impl AsRef<Path>,
258258
) -> Result<Metadata21> {
259-
let authors = cargo_toml.package.authors.join(", ");
259+
let authors = cargo_toml
260+
.package
261+
.authors
262+
.as_ref()
263+
.map(|authors| authors.join(", "));
260264

261265
let classifiers = cargo_toml.classifiers();
262266

263-
let author_email = if authors.contains('@') {
264-
Some(authors.clone())
265-
} else {
266-
None
267-
};
267+
let author_email = authors.as_ref().and_then(|authors| {
268+
if authors.contains('@') {
269+
Some(authors.clone())
270+
} else {
271+
None
272+
}
273+
});
268274

269275
let extra_metadata = cargo_toml.remaining_core_metadata();
270276

@@ -313,7 +319,7 @@ impl Metadata21 {
313319
home_page: cargo_toml.package.homepage.clone(),
314320
download_url: None,
315321
// Cargo.toml has no distinction between author and author email
316-
author: Some(authors),
322+
author: authors,
317323
author_email,
318324
license: cargo_toml.package.license.clone(),
319325

0 commit comments

Comments
 (0)