mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor: inline EncodableSourceId
deserialization
This commit is contained in:
parent
598cfab7e9
commit
6a97f6469a
@ -535,15 +535,13 @@ pub struct EncodableDependency {
|
|||||||
/// The serialization for `SourceId` doesn't do URL encode for parameters.
|
/// The serialization for `SourceId` doesn't do URL encode for parameters.
|
||||||
/// In contrast, this type is aware of that whenever [`ResolveVersion`] allows
|
/// In contrast, this type is aware of that whenever [`ResolveVersion`] allows
|
||||||
/// us to do so (v4 or later).
|
/// us to do so (v4 or later).
|
||||||
#[derive(Deserialize, Debug, PartialOrd, Ord, Clone)]
|
#[derive(Debug, PartialOrd, Ord, Clone)]
|
||||||
#[serde(transparent)]
|
|
||||||
pub struct EncodableSourceId {
|
pub struct EncodableSourceId {
|
||||||
inner: SourceId,
|
inner: SourceId,
|
||||||
/// We don't care about the deserialization of this, as the `url` crate
|
/// We don't care about the deserialization of this, as the `url` crate
|
||||||
/// will always decode as the URL was encoded. Only when a [`Resolve`]
|
/// will always decode as the URL was encoded. Only when a [`Resolve`]
|
||||||
/// turns into a [`EncodableResolve`] will it set the value accordingly
|
/// turns into a [`EncodableResolve`] will it set the value accordingly
|
||||||
/// via [`encodable_source_id`].
|
/// via [`encodable_source_id`].
|
||||||
#[serde(skip)]
|
|
||||||
encoded: bool,
|
encoded: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,6 +590,20 @@ impl ser::Serialize for EncodableSourceId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de> de::Deserialize<'de> for EncodableSourceId {
|
||||||
|
fn deserialize<D>(d: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: de::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = String::deserialize(d)?;
|
||||||
|
let sid = SourceId::from_url(&s).map_err(de::Error::custom)?;
|
||||||
|
Ok(EncodableSourceId {
|
||||||
|
inner: sid,
|
||||||
|
encoded: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::hash::Hash for EncodableSourceId {
|
impl std::hash::Hash for EncodableSourceId {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
self.inner.hash(state)
|
self.inner.hash(state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user