mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-25 14:20:31 +08:00
git-ref-format: fix to deserialization
When deserializing through `serde_json::from_value` the following
error would occur:
panicked at 'called Result::unwrap() on an Err value: Error("invalid
type: string "master", expected a borrowed string", line: 0, column:
0)'
To fix this it is necessary for the Deserialize implementations to
deserialize into an owned String and convert from there.
While attempting to test this the `Qualified` and `Namespaced`
implementations were not able to be used:
error: implementation of `serde::de::Deserialize` is not general enough
--> git-ref-format/t/src/properties/name.rs:86:9
|
86 | roundtrip::json_value(qualified);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
|
= note: `Qualified<'_>` must implement `serde::de::Deserialize<'0>`, for any lifetime `'0`...
= note: ...but `Qualified<'_>` actually implements
`serde::de::Deserialize<'1>`, for some specific lifetime `'1`
The Deserialize for both of those types now return owned data by
returning a 'static lifetime instead.
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -42,7 +42,8 @@ impl<'de> Deserialize<'de> for RefString {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Deserialize::deserialize(deserializer).map(|x: &RefStr| x.to_owned())
|
||||
Deserialize::deserialize(deserializer)
|
||||
.and_then(|x: String| Self::try_from(x).map_err(de::Error::custom))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +84,8 @@ impl<'de> Deserialize<'de> for PatternString {
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Deserialize::deserialize(deserializer).map(|x: &PatternStr| x.to_owned())
|
||||
Deserialize::deserialize(deserializer)
|
||||
.and_then(|x: String| Self::try_from(x).map_err(de::Error::custom))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,15 +99,17 @@ impl Serialize for PatternString {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de: 'a, 'a> Deserialize<'de> for Qualified<'a> {
|
||||
impl<'de> Deserialize<'de> for Qualified<'static> {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Deserialize::deserialize(deserializer).and_then(|s: &RefStr| {
|
||||
Deserialize::deserialize(deserializer).and_then(|s: String| {
|
||||
let s = RefString::try_from(s).map_err(de::Error::custom)?;
|
||||
s.qualified()
|
||||
.ok_or_else(|| de::Error::custom("not a qualified ref"))
|
||||
.map(|q| q.into_owned())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -120,15 +124,17 @@ impl Serialize for Qualified<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de: 'a, 'a> Deserialize<'de> for Namespaced<'a> {
|
||||
impl<'de> Deserialize<'de> for Namespaced<'static> {
|
||||
#[inline]
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
Deserialize::deserialize(deserializer).and_then(|s: &RefStr| {
|
||||
Deserialize::deserialize(deserializer).and_then(|s: String| {
|
||||
let s = RefString::try_from(s).map_err(de::Error::custom)?;
|
||||
s.to_namespaced()
|
||||
.ok_or_else(|| de::Error::custom("not a namespaced ref"))
|
||||
.map(|ns| ns.into_owned())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user