mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 03:39:31 +00:00
refactor(util-schemas): error type for RustVerion
This commit is contained in:
parent
d7b811b686
commit
90017c0747
|
@ -18,6 +18,7 @@ use serde_untagged::UntaggedEnumVisitor;
|
|||
|
||||
use crate::core::PackageIdSpec;
|
||||
use crate::core::PartialVersion;
|
||||
use crate::core::PartialVersionError;
|
||||
use crate::restricted_names;
|
||||
|
||||
/// This type is used to deserialize `Cargo.toml` files.
|
||||
|
@ -1334,15 +1335,15 @@ impl std::ops::Deref for RustVersion {
|
|||
}
|
||||
|
||||
impl std::str::FromStr for RustVersion {
|
||||
type Err = anyhow::Error;
|
||||
type Err = RustVersionError;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
let partial = value.parse::<PartialVersion>()?;
|
||||
if partial.pre.is_some() {
|
||||
anyhow::bail!("unexpected prerelease field, expected a version like \"1.32\"")
|
||||
return Err(RustVersionError::Prerelease);
|
||||
}
|
||||
if partial.build.is_some() {
|
||||
anyhow::bail!("unexpected prerelease field, expected a version like \"1.32\"")
|
||||
return Err(RustVersionError::BuildMetadata);
|
||||
}
|
||||
Ok(Self(partial))
|
||||
}
|
||||
|
@ -1366,6 +1367,20 @@ impl Display for RustVersion {
|
|||
}
|
||||
}
|
||||
|
||||
/// Error parsing a [`PartialVersion`].
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum RustVersionError {
|
||||
#[error("unexpected prerelease field, expected a version like \"1.32\"")]
|
||||
Prerelease,
|
||||
|
||||
#[error("unexpected build field, expected a version like \"1.32\"")]
|
||||
BuildMetadata,
|
||||
|
||||
#[error(transparent)]
|
||||
PartialVersion(#[from] PartialVersionError),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct InvalidCargoFeatures {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue