Skip to content

Commit 6a97f64

Browse files
committed
refactor: inline EncodableSourceId deserialization
1 parent 598cfab commit 6a97f64

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/cargo/core/resolver/encode.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,13 @@ pub struct EncodableDependency {
535535
/// The serialization for `SourceId` doesn't do URL encode for parameters.
536536
/// In contrast, this type is aware of that whenever [`ResolveVersion`] allows
537537
/// us to do so (v4 or later).
538-
#[derive(Deserialize, Debug, PartialOrd, Ord, Clone)]
539-
#[serde(transparent)]
538+
#[derive(Debug, PartialOrd, Ord, Clone)]
540539
pub struct EncodableSourceId {
541540
inner: SourceId,
542541
/// We don't care about the deserialization of this, as the `url` crate
543542
/// will always decode as the URL was encoded. Only when a [`Resolve`]
544543
/// turns into a [`EncodableResolve`] will it set the value accordingly
545544
/// via [`encodable_source_id`].
546-
#[serde(skip)]
547545
encoded: bool,
548546
}
549547

@@ -592,6 +590,20 @@ impl ser::Serialize for EncodableSourceId {
592590
}
593591
}
594592

593+
impl<'de> de::Deserialize<'de> for EncodableSourceId {
594+
fn deserialize<D>(d: D) -> Result<Self, D::Error>
595+
where
596+
D: de::Deserializer<'de>,
597+
{
598+
let s = String::deserialize(d)?;
599+
let sid = SourceId::from_url(&s).map_err(de::Error::custom)?;
600+
Ok(EncodableSourceId {
601+
inner: sid,
602+
encoded: false,
603+
})
604+
}
605+
}
606+
595607
impl std::hash::Hash for EncodableSourceId {
596608
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
597609
self.inner.hash(state)

0 commit comments

Comments
 (0)