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
use crate::project::manifest::{FeatureName, TargetSelector};
use crate::project::SpecType;
use miette::Diagnostic;
use thiserror::Error;
/// An error that is returned when a certain spec is missing.
#[derive(Debug, Error, Diagnostic)]
#[error("{name} is missing")]
pub struct SpecIsMissing {
// The name of the dependency that is missing,
pub name: String,
// The type of the dependency that is missing.
pub spec_type: SpecType,
/// Whether the dependency itself is missing or the entire dependency spec type is missing
pub spec_type_is_missing: bool,
// The target from which the dependency is missing.
pub target: Option<TargetSelector>,
// The feature from which the dependency is missing.
pub feature: Option<FeatureName>,
}
impl SpecIsMissing {
/// Constructs a new `SpecIsMissing` error that indicates that a spec type is missing.
///
/// This is constructed for instance when the `[build-dependencies]` section is missing.
pub fn spec_type_is_missing(name: impl Into<String>, spec_type: SpecType) -> Self {
Self {
name: name.into(),
spec_type,
spec_type_is_missing: true,
target: None,
feature: None,
}
}
/// Constructs a new `SpecIsMissing` error that indicates that a spec is missing
pub fn dep_is_missing(name: impl Into<String>, spec_type: SpecType) -> Self {
Self {
name: name.into(),
spec_type,
spec_type_is_missing: false,
target: None,
feature: None,
}
}
/// Set the target from which the spec is missing.
pub fn with_target(mut self, target: TargetSelector) -> Self {
self.target = Some(target);
self
}
/// Sets the feature from which the spec is missing.
pub fn with_feature(mut self, feature: FeatureName) -> Self {
self.feature = Some(feature);
self
}
}