mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
with_precise as a helper
This commit is contained in:
parent
d2d210257f
commit
22f4352c29
@ -468,48 +468,30 @@ impl SourceId {
|
|||||||
|
|
||||||
/// Creates a new `SourceId` from this source with the given `precise`.
|
/// Creates a new `SourceId` from this source with the given `precise`.
|
||||||
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
|
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
|
||||||
let precise = fragment.map(|f| Precise::GitUrlFragment(f));
|
self.with_precise(&fragment.map(|f| Precise::GitUrlFragment(f)))
|
||||||
if self.inner.precise == precise {
|
|
||||||
self
|
|
||||||
} else {
|
|
||||||
SourceId::wrap(SourceIdInner {
|
|
||||||
precise,
|
|
||||||
..(*self.inner).clone()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `SourceId` from this source without a `precise`.
|
/// Creates a new `SourceId` from this source without a `precise`.
|
||||||
pub fn without_precise(self) -> SourceId {
|
pub fn without_precise(self) -> SourceId {
|
||||||
if self.inner.precise.is_none() {
|
self.with_precise(&None)
|
||||||
self
|
|
||||||
} else {
|
|
||||||
SourceId::wrap(SourceIdInner {
|
|
||||||
precise: None,
|
|
||||||
..(*self.inner).clone()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `SourceId` from this source without a `precise`.
|
/// Creates a new `SourceId` from this source without a `precise`.
|
||||||
pub fn with_locked_precise(self) -> SourceId {
|
pub fn with_locked_precise(self) -> SourceId {
|
||||||
if self.inner.precise == Some(Precise::Locked) {
|
self.with_precise(&Some(Precise::Locked))
|
||||||
self
|
|
||||||
} else {
|
|
||||||
SourceId::wrap(SourceIdInner {
|
|
||||||
precise: Some(Precise::Locked),
|
|
||||||
..(*self.inner).clone()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
|
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
|
||||||
pub fn with_precise_from(self, v: Self) -> SourceId {
|
pub fn with_precise_from(self, v: Self) -> SourceId {
|
||||||
if self.inner.precise == v.inner.precise {
|
self.with_precise(&v.inner.precise)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_precise(self, precise: &Option<Precise>) -> SourceId {
|
||||||
|
if &self.inner.precise == precise {
|
||||||
self
|
self
|
||||||
} else {
|
} else {
|
||||||
SourceId::wrap(SourceIdInner {
|
SourceId::wrap(SourceIdInner {
|
||||||
precise: v.inner.precise.clone(),
|
precise: precise.clone(),
|
||||||
..(*self.inner).clone()
|
..(*self.inner).clone()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user