-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathrequested.rs
More file actions
71 lines (63 loc) · 1.91 KB
/
Copy pathrequested.rs
File metadata and controls
71 lines (63 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::fmt::{Display, Formatter};
use crate::{
Dist, DistributionId, DistributionMetadata, Identifier, InstalledDist, Name, ResourceId,
VersionOrUrlRef,
};
use uv_normalize::PackageName;
use uv_pep440::Version;
/// A distribution that can be requested during resolution.
///
/// Either an already-installed distribution or a distribution that can be installed.
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum RequestedDist {
Installed(InstalledDist),
Installable(Dist),
}
impl RequestedDist {
/// Returns the version of the distribution, if it is known.
pub fn version(&self) -> Option<&Version> {
match self {
Self::Installed(dist) => Some(dist.version()),
Self::Installable(dist) => dist.version(),
}
}
}
impl Name for RequestedDist {
fn name(&self) -> &PackageName {
match self {
Self::Installable(dist) => dist.name(),
Self::Installed(dist) => dist.name(),
}
}
}
impl DistributionMetadata for RequestedDist {
fn version_or_url(&self) -> VersionOrUrlRef {
match self {
Self::Installed(dist) => dist.version_or_url(),
Self::Installable(dist) => dist.version_or_url(),
}
}
}
impl Identifier for RequestedDist {
fn distribution_id(&self) -> DistributionId {
match self {
Self::Installed(dist) => dist.distribution_id(),
Self::Installable(dist) => dist.distribution_id(),
}
}
fn resource_id(&self) -> ResourceId {
match self {
Self::Installed(dist) => dist.resource_id(),
Self::Installable(dist) => dist.resource_id(),
}
}
}
impl Display for RequestedDist {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Installed(dist) => dist.fmt(f),
Self::Installable(dist) => dist.fmt(f),
}
}
}