Validate package and extra name (#290)

`PackageName` and `ExtraName` can now only be constructed from valid
names. They share the same rules, so i gave them the same
implementation. Constructors are split between `new` (owned) and
`from_str` (borrowed), with the owned version avoiding allocations.

Closes #279

---------

Co-authored-by: Zanie <contact@zanie.dev>
This commit is contained in:
konsti 2023-11-06 11:04:31 +01:00 committed by GitHub
parent ea28b3d0d3
commit 81f380b10e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 258 additions and 171 deletions

View file

@ -53,7 +53,7 @@ impl PubGrubDependencies {
.clone()
.into_iter()
.flatten()
.map(|extra| to_pubgrub(requirement, Some(ExtraName::new(extra)))),
.map(|extra| to_pubgrub(requirement, Some(extra))),
) {
let (package, version) = result?;
@ -101,7 +101,7 @@ impl PubGrubDependencies {
.clone()
.into_iter()
.flatten()
.map(|extra| to_pubgrub(constraint, Some(ExtraName::new(extra)))),
.map(|extra| to_pubgrub(constraint, Some(extra))),
) {
let (package, version) = result?;

View file

@ -518,7 +518,7 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
if !metadata
.provides_extras
.iter()
.any(|provided_extra| ExtraName::new(provided_extra) == *extra)
.any(|provided_extra| provided_extra == extra)
{
return Ok(Dependencies::Unknown);
}